-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an convenient Artifact to use FlowReduxStateMachine
in compose
#236
Conversation
compileSdk : 30, | ||
targetSdk : 30, | ||
compileSdk : 31, | ||
targetSdk : 31, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also updates compile + target SDK to 31
(then some other DependABot created PRs should compile)
|
||
val errorMessage = stringResource(R.string.unexpected_error) | ||
if (showErrorSnackBar) { | ||
LaunchedEffect(scaffoldState.snackbarHostState) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually not 100% sure if this works as intended because of the surrounding if (showErrorSnackBar)
... It seems to work, but here I don't understand how LaunchedEffect(key)
learns that the key = scaffoldState.snackbarHostState
has changed if it surrounded by an if(showErrorSnackBar)
...
} | ||
|
||
if (loadMore) { | ||
LaunchedEffect(loadMore) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
suspend fun loadPage(page: Int): PageResult { | ||
delay(300) | ||
delay(2000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
increased to see things better in the Sample Application UI
).run { | ||
// TODO rewrite this to use header Link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will never happen 😄 therefore removed this comment 😺
* Instead the "wrappter class" [PaginationStateMachine] should be used which hides `Flow` etc. | ||
* but uses traditional "callbacks". That way it is easier to use on iOS. | ||
*/ | ||
class InternalPaginationStateMachine( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to only expose publicly PaginationStateMachine
and not this class InternalPaginationStateMachine
because PaginationStateMachine
provides traditional callback based listener so that from iOS you don't need to bridge Flow
and suspend function
.
but compose actually should access directly a FlowReduxStateMachine
to be able to use extension functions like stateAndDispatch()
on it. Therefore made it public.
private val logger: FlowReduxLogger? = null | ||
) : StateMachine<S, A> { | ||
|
||
val initialState: S by lazy(LazyThreadSafetyMode.NONE, initialStateSupplier) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So initial state will be kept forever. That ensures that it is always the same initial state for all state:Flow<MyState>
collectors. Also with making this public, FlowReduxStateMachine.asState()
Compose extension can access it and return type is State<MyState>
instead of nullable State<MyState?>
as it serves as the initial state in produceState {...}
.
sample/android/src/main/java/com/freeletics/flowredux/compose/PopularRepositoriesUi.kt
Outdated
Show resolved
Hide resolved
Closes #139 |
Adds a way to subscribe to state in compose:
MyFlowReduxStateMachine.asState()
and a way to get both, subscribe to state and dispatch actions:
val (state : State<MyState>, dispatch : (MyAction) -> Unit) = MyFlowReduxStateMachine.stateAndDispatch()
I have also added a compose code sample. For sure it can be made nicer or more idiomatic, but does the job so far I guess.