-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #632 from square/ray/embrace-the-viewmodel
WorkflowLayout.start needs a Lifecycle, BackStackScreen is supported.
- Loading branch information
Showing
24 changed files
with
171 additions
and
107 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
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
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
23 changes: 0 additions & 23 deletions
23
samples/containers/android/src/main/java/com/squareup/sample/container/BackButtonScreen.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...s/containers/android/src/main/java/com/squareup/sample/container/BackButtonViewFactory.kt
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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
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
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
43 changes: 43 additions & 0 deletions
43
workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/BackButtonScreen.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,43 @@ | ||
package com.squareup.workflow1.ui | ||
|
||
/** | ||
* Adds optional back button handling to a [wrapped] rendering, possibly overriding that | ||
* the wrapped rendering's own back button handler. | ||
* | ||
* @param shadow If `true`, [onBackPressed] is set as the | ||
* [backPressedHandler][android.view.View.backPressedHandler] after | ||
* the [wrapped] rendering's view is built / updated, effectively overriding it. | ||
* If false (the default), [onBackPressed] is set afterward, to allow the wrapped rendering to | ||
* take precedence if it sets a `backPressedHandler` of its own -- the handler provided | ||
* here serves as a default. | ||
* | ||
* @param onBackPressed The function to fire when the device back button | ||
* is pressed, or null to set no handler -- or clear a handler that was set previously. | ||
* Defaults to `null`. | ||
*/ | ||
@WorkflowUiExperimentalApi | ||
public class BackButtonScreen<W : Any>( | ||
public val wrapped: W, | ||
public val shadow: Boolean = false, | ||
public val onBackPressed: (() -> Unit)? = null | ||
) : AndroidViewRendering<BackButtonScreen<*>> { | ||
override val viewFactory: ViewFactory<BackButtonScreen<*>> = DecorativeViewFactory( | ||
type = BackButtonScreen::class, | ||
map = { outer -> outer.wrapped }, | ||
doShowRendering = { view, innerShowRendering, outerRendering, viewEnvironment -> | ||
if (!outerRendering.shadow) { | ||
// Place our handler before invoking innerShowRendering, so that | ||
// its later calls to view.backPressedHandler will take precedence | ||
// over ours. | ||
view.backPressedHandler = outerRendering.onBackPressed | ||
} | ||
|
||
innerShowRendering.invoke(outerRendering.wrapped, viewEnvironment) | ||
|
||
if (outerRendering.shadow) { | ||
// Place our handler after invoking innerShowRendering, so that ours wins. | ||
view.backPressedHandler = outerRendering.onBackPressed | ||
} | ||
} | ||
) | ||
} |
Oops, something went wrong.