-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracts
ScreenViewFactory.map
from ScreenViewFactory.forWrapper
Coupling `Wrapper` to `ScreenViewFactory.forWrapper` was a mistake, made simple transformations that weren't in the strict `Wrapper` shape more difficult. Also some compulsive tidying of sample code. Fixes #973
- Loading branch information
Showing
13 changed files
with
209 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
samples/containers/common/src/main/java/com/squareup/sample/container/panel/ScrimScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package com.squareup.sample.container.panel | ||
|
||
import com.squareup.workflow1.ui.Compatible | ||
import com.squareup.workflow1.ui.Compatible.Companion.keyFor | ||
import com.squareup.workflow1.ui.Screen | ||
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
import com.squareup.workflow1.ui.Wrapper | ||
|
||
/** | ||
* Show a scrim over some [content], which is invisible if [dimmed] is false, | ||
* visible if it is true. | ||
*/ | ||
@OptIn(WorkflowUiExperimentalApi::class) | ||
class ScrimScreen<T : Screen>( | ||
val content: T, | ||
class ScrimScreen<C : Screen>( | ||
override val content: C, | ||
val dimmed: Boolean | ||
) : Screen, Compatible { | ||
override val compatibilityKey = keyFor(content, "ScrimScreen") | ||
) : Wrapper<Screen, C>, Screen { | ||
override fun <D : Screen> map(transform: (C) -> D) = ScrimScreen(transform(content), dimmed) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 0 additions & 38 deletions
38
...k-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonLayoutRunner.kt
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...lo-back-button/src/main/java/com/squareup/sample/hellobackbutton/HelloBackButtonScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@file:Suppress("ktlint:filename") | ||
|
||
package com.squareup.sample.hellobackbutton | ||
|
||
import com.squareup.sample.hellobackbutton.databinding.HelloBackButtonLayoutBinding | ||
import com.squareup.workflow1.ui.AndroidScreen | ||
import com.squareup.workflow1.ui.ScreenViewFactory | ||
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
import com.squareup.workflow1.ui.backPressedHandler | ||
|
||
@OptIn(WorkflowUiExperimentalApi::class) | ||
data class HelloBackButtonScreen( | ||
val message: String, | ||
val onClick: () -> Unit, | ||
val onBackPressed: (() -> Unit)? | ||
) : AndroidScreen<HelloBackButtonScreen> { | ||
override val viewFactory: ScreenViewFactory<HelloBackButtonScreen> = | ||
ScreenViewFactory.fromViewBinding(HelloBackButtonLayoutBinding::inflate) { rendering, _ -> | ||
helloMessage.text = rendering.message | ||
helloMessage.setOnClickListener { rendering.onClick() } | ||
helloMessage.backPressedHandler = rendering.onBackPressed | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.