Skip to content
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

[Fragment] Add onNewInstance callback. #323

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Conversation

Laimiux
Copy link
Collaborator

@Laimiux Laimiux commented Dec 12, 2023

What

Removing onFirstModel callback in favor of exposing onNewInstance and moving the first model logic out of the core library.

val end = SystemClock.uptimeMillis()

firstRender = false
fragmentDelegate.onFirstModelRendered(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this anymore because we can use onNewInstance with setOutput to fire the first model render

@carrotkite
Copy link

JaCoCo Code Coverage 79.66% ✅

Class Covered Meta Status
com/instacart/formula/android/FragmentEnvironment 100% 0%
com/instacart/formula/android/FormulaFragment 82% 0%
com/instacart/formula/android/internal/FragmentFlowRenderView 70% 0%
com/instacart/formula/android/internal/FragmentLifecycle 70% 0%

Generated by 🚫 Danger

* Creates a unique identifier the first time fragment is attached that
* is persisted across configuration changes.
*/
private fun initializeFragmentInstanceIdIfNeeded(f: Fragment) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into getFormulaFragmentId

@Laimiux Laimiux force-pushed the laimonas/on-new-instance branch from 2449d07 to ab6dd4c Compare December 12, 2023 21:29
Comment on lines +47 to +63
return if (this is BaseFormulaFragment<*>) {
val arguments = arguments ?: run {
Bundle().apply {
arguments = this
}
}
val id = arguments.getString(FormulaFragment.ARG_FORMULA_ID, "")
if (id.isNullOrBlank()) {
val initializedId = UUID.randomUUID().toString()
arguments.putString(FormulaFragment.ARG_FORMULA_ID, initializedId)
initializedId
} else {
id
}
} else {
""
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we cover this logic with tests?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question - we already cover this logic via tests in the formula-android and formula-android-tests modules. Specifically, the most important tests are the following:

@Laimiux Laimiux merged commit 62c935f into master Dec 12, 2023
5 checks passed
@Laimiux Laimiux deleted the laimonas/on-new-instance branch December 12, 2023 21:49
Laimiux added a commit that referenced this pull request Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants