Skip to content

fix(Android): Differentiate between new and preloaded screens in ScreenStack #3062

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

Merged
merged 7 commits into from
Jul 28, 2025

Conversation

kmichalikk
Copy link
Collaborator

@kmichalikk kmichalikk commented Jul 23, 2025

Description

Closes #3004.

When onUpdate is issued for ScreenStack, we have no way of knowing whether the screen that is on top with state=2 was already on top or was preloaded with state=0, so we need to store this information somehow, i.e in a list.

Changes

Added preloadedWrappers list to ScreenStack class and update it at the end of each onUpdate.

Test code and steps to reproduce

See Test3004

@kmichalikk kmichalikk force-pushed the @kmichalikk/activity-state-wrong-animation-3004 branch from 400fef5 to a8f818a Compare July 23, 2025 07:00
@kmichalikk kmichalikk requested a review from kkafar July 23, 2025 07:05
@maciekstosio
Copy link
Contributor

I wonder how this solution relates to #2945

@kmichalikk
Copy link
Collaborator Author

Looks like both solve the same problem and work with the examples. The flag is less elegant but more local, and the second one might break something else.

@kmichalikk kmichalikk changed the title fix(Android): Add isBeingActivated flag to differentiate between new and preloaded screens fix(Android): Differentiate between new and preloaded screens in ScreenStack Jul 24, 2025
@@ -148,7 +149,7 @@ class ScreenStack(
var shouldUseOpenAnimation = true
var stackAnimation: StackAnimation? = null

val newTopAlreadyInStack = stack.contains(newTop)
val newTopAlreadyInStack = stack.contains(newTop) && !preloadedWrappers.contains(newTop)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should add a comment explaining new semantics of newTopAlreadyInStack.

Comment on lines 266 to 269
preloadedWrappers = screenWrappers
.asSequence()
.filter { it.screen.activityState == Screen.ActivityState.INACTIVE }
.toList()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure here if all screens with inactive state are preloaded. Please add a comment abot this assumption here.

flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: 'rgba(0.2, 0.2, 0.4, 0.3)'
Copy link
Contributor

Choose a reason for hiding this comment

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

Where possible, you can use colors from apps/src/shared/styling/Colors.ts

Comment on lines 144 to 145
export { default as Test3004a } from './Test3004a';
export { default as Test3004b } from './Test3004b';
Copy link
Contributor

Choose a reason for hiding this comment

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

These test names won't work with current sorting logic in example app. You can try using 3004.1 & 3004.2 or use issue number and PR number.

@@ -303,6 +304,7 @@ class Screen(
}

fun setActivityState(activityState: ActivityState) {
Log.d("RNScreens", "Activity state updated to %s".format(activityState.toString()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to remove logs and redundant imports. Applies also to ScreenStack.kt

apps/App.tsx Outdated
Comment on lines 9 to 10
return <Example />;
// return <Test.Test3004_1 />;
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to leave this file as it was if Example app does not work properly without Reanimated/GestureHandler.

@@ -148,7 +150,8 @@ class ScreenStack(
var shouldUseOpenAnimation = true
var stackAnimation: StackAnimation? = null

val newTopAlreadyInStack = stack.contains(newTop)
// We don't count preloaded screen as "already in stack"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd consider adding more details why this is the case. You can also link to this PR if you think it would help.

Copy link
Contributor

@maciekstosio maciekstosio left a comment

Choose a reason for hiding this comment

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

Rest seems good

}

function Modal({ navigation }: StackNavigationProp) {
return (<View style={{
Copy link
Contributor

Choose a reason for hiding this comment

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

Small nitpick, wouldn't it be more readable to move parentheses to separate like in *_1 example?

@kmichalikk kmichalikk requested a review from kligarski July 25, 2025 08:40
@@ -150,7 +149,8 @@ class ScreenStack(
var shouldUseOpenAnimation = true
var stackAnimation: StackAnimation? = null

// We don't count preloaded screen as "already in stack"
// We don't count preloaded screen as "already in stack" up until it appears with state == ON_TOP
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// We don't count preloaded screen as "already in stack" up until it appears with state == ON_TOP
// We don't count preloaded screen as "already in stack" until it appears with state == ON_TOP

@kmichalikk kmichalikk force-pushed the @kmichalikk/activity-state-wrong-animation-3004 branch from ac1f77e to f15955e Compare July 28, 2025 11:48
@kmichalikk kmichalikk requested a review from kligarski July 28, 2025 11:48
@kmichalikk kmichalikk merged commit 233ddd8 into main Jul 28, 2025
2 of 3 checks passed
@kmichalikk kmichalikk deleted the @kmichalikk/activity-state-wrong-animation-3004 branch July 28, 2025 11:55
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.

[Android] When presenting preloaded screen in stack, wrong animation is used
4 participants