-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update docs for
childOverlay
with custom component context
- Loading branch information
Showing
4 changed files
with
135 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# How to initialize Child Overlay with custom ComponentContext | ||
|
||
In order to pass this `AppComponentContext` to child overlay components, make an extension function on the `AppComponentContext` interface. This custom extension function will initialize the `Child Overlay` and provide child `AppComponentContext`. | ||
|
||
```kotlin | ||
fun <C : Parcelable, T : Any> AppComponentContext.appChildOverlay( | ||
source: OverlayNavigationSource<C>, | ||
initialConfiguration: () -> C?, | ||
configurationClass: KClass<out C>, | ||
key: String = "DefaultOverlay", | ||
handleBackButton: Boolean = false, | ||
persistent: Boolean = false, | ||
childFactory: (configuration: C, AppComponentContext) -> T | ||
): Value<ChildOverlay<C, T>> = | ||
childOverlay( | ||
source = source, | ||
configurationClass = configurationClass, | ||
key = key, | ||
handleBackButton = handleBackButton, | ||
initialConfiguration = initialConfiguration, | ||
persistent = persistent | ||
) { configuration, componentContext -> | ||
childFactory( | ||
configuration, | ||
DefaultAppComponentContext( | ||
componentContext = componentContext, | ||
bundleId, | ||
settings, | ||
boarding | ||
) | ||
) | ||
} | ||
|
||
inline fun <reified C : Parcelable, T : Any> AppComponentContext.appChildStack( | ||
source: OverlayNavigationSource<C>, | ||
noinline initialConfiguration: () -> C?, | ||
key: String = "DefaultOverlay", | ||
handleBackButton: Boolean = false, | ||
persistent: Boolean = false, | ||
noinline childFactory: (configuration: C, AppComponentContext) -> T | ||
): Value<ChildOverlay<C, T>> = | ||
appChildOverlay( | ||
source = source, | ||
initialConfiguration = initialConfiguration, | ||
configurationClass = C::class, | ||
key = key, | ||
handleBackButton = handleBackButton, | ||
persistent = persistent, | ||
childFactory = childFactory, | ||
) | ||
``` | ||
|
||
Finally, in your components you can create the new extension function that will utilize the new custom `AppComponentContext`. | ||
|
||
```kotlin | ||
class MyComponent(componentContext: AppComponentContext) : AppComponentContext by componentContext { | ||
|
||
private val navigation = OverlayNavigation<Configuration>() | ||
|
||
private val childStack = appChildOverlay( | ||
source = navigation, | ||
persistent = false, | ||
handleBackButton = true, | ||
childFactory = { configuration, appComponentContext -> { | ||
// return child components using the custom component context | ||
} | ||
) | ||
} | ||
``` |
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,61 @@ | ||
# How to initialize Child Stack with custom ComponentContext | ||
|
||
In order to pass this `AppComponentContext` to child components, make an extension function on the `AppComponentContext` interface. This custom extension function will initialize the `Child Stack` and provide child `AppComponentContext`. | ||
|
||
```kotlin | ||
fun <C : Parcelable, T : Any> AppComponentContext.appChildStack( | ||
source: StackNavigationSource<C>, | ||
initialStack: () -> List<C>, | ||
configurationClass: KClass<out C>, | ||
key: String = "DefaultStack", | ||
handleBackButton: Boolean = false, | ||
childFactory: (configuration: C, AppComponentContext) -> T | ||
): Value<ChildStack<C, T>> = | ||
childStack( | ||
source = source, | ||
initialStack = initialStack, | ||
configurationClass = configurationClass, | ||
key = key, | ||
handleBackButton = handleBackButton | ||
) { configuration, componentContext -> | ||
childFactory( | ||
configuration, | ||
DefaultAppComponentContext( | ||
componentContext = componentContext | ||
) | ||
) | ||
} | ||
|
||
inline fun <reified C : Parcelable, T : Any> AppComponentContext.appChildStack( | ||
source: StackNavigationSource<C>, | ||
noinline initialStack: () -> List<C>, | ||
key: String = "DefaultStack", | ||
handleBackButton: Boolean = false, | ||
noinline childFactory: (configuration: C, AppComponentContext) -> T | ||
): Value<ChildStack<C, T>> = | ||
appChildStack( | ||
source = source, | ||
initialStack = initialStack, | ||
configurationClass = C::class, | ||
key = key, | ||
handleBackButton = handleBackButton, | ||
childFactory = childFactory, | ||
) | ||
``` | ||
|
||
Finally, in your components you can create the new extension function that will utilize the new custom `AppComponentContext`. | ||
|
||
```kotlin | ||
class MyComponent(componentContext: AppComponentContext) : AppComponentContext by componentContext { | ||
|
||
private val navigation = StackNavigation<Configuration>() | ||
|
||
private val childStack = appChildStack( | ||
source = navigation, | ||
initialStack = { listOf(Configuration.Home) }, | ||
childFactory = { configuration, appComponentContext -> | ||
// return child components using the custom component context | ||
} | ||
) | ||
} | ||
``` |
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