-
Notifications
You must be signed in to change notification settings - Fork 100
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
Fix the double showRendering call when initializing DecorativeViewFactory views. #276
Conversation
13b5e7d
to
fd8fd30
Compare
/** | ||
* TODO kdoc | ||
*/ | ||
@WorkflowUiExperimentalApi | ||
public fun interface ViewInitializer { | ||
/** | ||
* TODO kdoc | ||
* | ||
* Implementations of this function _must_ call [showRendering]. | ||
*/ |
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.
TODO
a754051
to
c2a3628
Compare
* | ||
* Implementations of this function _must_ call [showRendering]. | ||
*/ | ||
public fun onViewCreated(view: View) |
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.
Note to self: If it's important that ViewStateCache
only call restoreSavedInstanceState
after the view's initial showRendering
, then this will either have to be changed to allow initializers to run code both before and after the showRendering
call, or we'll need two update
functions that BackStackContainer
s will be required to call.
I'm leaning towards the latter – it keeps this API much simpler and more focused, and while it makes the ViewStateCache
API more complex, the extra verbosity might actually make the code more clear.
That said, adding a proceed
function parameter here would mean bindShowRendering
could drop it's magic "if the tag changed, don't call showRendering" logic, and instead leave it up to the ViewInitializer to skip calling proceed if it wants to. ViewStateCache
also needs to track some local state before and after the initial showRendering, which would be easier to do if it could control that call.
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.
Is this different than the existing initView
and doShowRendering
arguments to DecorativeViewFactory
?
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.
initView is called in the same point in the initialization process, so they are related.
But it's different than initView in that it's not tied to a particular view factory, but to a particular invocation of buildView.
doShowRendering is unrelated though, that gets called on every update.
workflow-ui/core-android/src/main/java/com/squareup/workflow1/ui/DecorativeViewFactory.kt
Show resolved
Hide resolved
* | ||
* Implementations of this function _must_ call [showRendering]. | ||
*/ | ||
public fun onViewCreated(view: View) |
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.
Is this different than the existing initView
and doShowRendering
arguments to DecorativeViewFactory
?
c2a3628
to
f848144
Compare
0eebbdc
to
9c020a3
Compare
ee289ed
to
93a0802
Compare
9c020a3
to
3825922
Compare
93a0802
to
7d6cc65
Compare
3825922
to
9eb00a1
Compare
adc7223
to
a6bd9b5
Compare
* | ||
* @param view The [View] that was just created by the [ViewFactory]. | ||
*/ | ||
public fun onViewCreated(view: View) |
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.
cc @laurakelly i removed that parameter like we discussed.
…tory views. Introduces `ViewInitializer` which gets executed by `bindShowRendering` between setting the tag and actually invoking `showRendering`, which gives the `DecorativeViewFactory` logic the chance to cancel the original `showRendering` call since it wraps it. This initializer concept will also be used in a follow-up PR to allow `ViewStateCache` to correctly initialize AndroidX view tree owners.
a6bd9b5
to
bd6daca
Compare
So I thought this would be required to implement AndroidX ViewTreeOwners support, but I sketched out an idea in #280 that doesn't actually require this at all. I haven't tested that yet though so it might need this after all. But if it doesn't, then I think this is probably too over-engineered just to solve this one case, and we should rethink how to fix the double-render. |
This was made obsolete by #397, I believe. |
Introduces
ViewInitializer
which gets executed bybindShowRendering
between settingthe tag and actually invoking
showRendering
, which gives theDecorativeViewFactory
logic the chance to cancel the original
showRendering
call since it wraps it.This initializer concept will also be used in a follow-up PR to allow
ViewStateCache
to correctly initialize AndroidX view tree owners.