-
-
Notifications
You must be signed in to change notification settings - Fork 614
fix(Android, Stack, Fabric): Fix jumping content in nested stack for Fabric #3442
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
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6979be3
Fix content jump for AppBarLayout
t0maboro a521f13
Add example for testing
t0maboro 195f125
Minor cleanup before fixing content
t0maboro b6844ba
Try fixing with DummyLayoutHelper - still observing some flickers
t0maboro 5548ab7
Synchronize shadow states with DecorView insets
t0maboro 67a2a02
Cleanup
t0maboro 946e1f5
Remove old note
t0maboro 3019b09
Fix for header hidden
t0maboro cdff65d
Fix header transparent
t0maboro 59a9a9f
Update comment
t0maboro a4df45a
Alternative instead of max
t0maboro 364bb05
Remove API lvl 30 check
t0maboro 851c345
Remove object
t0maboro 13bded5
Remove obsolete DecorView height correction
t0maboro 07101c6
Drop reckless statement
t0maboro b4247d5
Rename
t0maboro cf77523
Handle DecorView insets only for top-level components
t0maboro b131e5f
Linter
t0maboro 65daeea
Revert "Handle DecorView insets only for top-level components"
t0maboro c7895b1
Respect only highest screen with header
t0maboro 052e833
Revert "Respect only highest screen with header"
t0maboro 955d588
Add comment
t0maboro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
android/src/main/java/com/swmansion/rnscreens/CustomAppBarLayout.kt
This file contains hidden or 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,25 @@ | ||
| package com.swmansion.rnscreens | ||
|
|
||
| import android.annotation.SuppressLint | ||
| import android.content.Context | ||
| import com.google.android.material.appbar.AppBarLayout | ||
|
|
||
| @SuppressLint("ViewConstructor") | ||
| class CustomAppBarLayout( | ||
| context: Context, | ||
| ) : AppBarLayout(context) { | ||
| /** | ||
| * Handles the layout correction from the child Toolbar. | ||
| */ | ||
| internal fun onToolbarLayout(toolbarPaddingTop: Int) { | ||
| applyFrameCorrectionByTopInset(toolbarPaddingTop) | ||
| } | ||
|
|
||
| private fun applyFrameCorrectionByTopInset(topInset: Int) { | ||
| measure( | ||
| MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), | ||
| MeasureSpec.makeMeasureSpec(height + topInset, MeasureSpec.EXACTLY), | ||
| ) | ||
| layout(left, top, right, bottom + topInset) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
25 changes: 25 additions & 0 deletions
25
android/src/main/java/com/swmansion/rnscreens/utils/DecorViewInsetsUtils.kt
This file contains hidden or 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,25 @@ | ||
| package com.swmansion.rnscreens.utils | ||
|
|
||
| import android.view.View | ||
| import androidx.core.view.ViewCompat | ||
| import androidx.core.view.WindowInsetsCompat | ||
|
|
||
| object DecorViewInsetsUtils { | ||
| /** | ||
| * Retrieves the top system inset (such as status bar or display cutout) from the given decor view. | ||
| * | ||
| * @param decorView The top-level window decor view. | ||
| * @return The top inset in pixels. | ||
| */ | ||
| internal fun getDecorViewTopInset(decorView: View): Int { | ||
| val insetsCompat = ViewCompat.getRootWindowInsets(decorView) ?: return 0 | ||
|
|
||
| return getTopInset(insetsCompat) | ||
| } | ||
|
|
||
| private fun getTopInset(insetsCompat: WindowInsetsCompat): Int = | ||
| insetsCompat | ||
| .getInsets( | ||
| WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout(), | ||
| ).top | ||
| } | ||
kkafar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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 hidden or 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,113 @@ | ||
| import React from 'react'; | ||
| import { View, Text, StyleSheet, Button } from 'react-native'; | ||
| import { NavigationContainer } from '@react-navigation/native'; | ||
| import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; | ||
| import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
| import { SafeAreaProvider } from 'react-native-safe-area-context'; | ||
| import Colors from '../shared/styling/Colors'; | ||
|
|
||
| type RootTabParamList = { | ||
| First: undefined; | ||
| Second: undefined; | ||
| Third: undefined; | ||
| }; | ||
|
|
||
| type InnerScreenName = | ||
| | 'Inner11' | 'Inner12' | 'Inner13' | ||
| | 'Inner21' | 'Inner22' | 'Inner23' | ||
| | 'Inner31' | 'Inner32' | 'Inner33'; | ||
|
|
||
| const Tab = createBottomTabNavigator<RootTabParamList>(); | ||
| const Stack = createNativeStackNavigator<any>(); | ||
|
|
||
| type ScreenProps = { | ||
| current: InnerScreenName; | ||
| next?: InnerScreenName; | ||
| }; | ||
|
|
||
| const Screen = ({ current, next, navigation }: ScreenProps & { navigation: any }) => ( | ||
| <View style={styles.container}> | ||
| <Text>{`${current} Screen`}</Text> | ||
| {next && ( | ||
| <Button title="Forward" onPress={() => navigation.navigate(next)} /> | ||
| )} | ||
| </View> | ||
| ); | ||
|
|
||
| const createScreen = (current: InnerScreenName, next?: InnerScreenName) => | ||
| function ScreenWrapper({ navigation }: { navigation: any }) { | ||
| return <Screen current={current} next={next} navigation={navigation} />; | ||
| }; | ||
|
|
||
| const screenGroups: Record<string, { screens: InnerScreenName[]; headerColor: string; contentColor: string }> = { | ||
| First: { | ||
| screens: ['Inner11', 'Inner12', 'Inner13'], | ||
| headerColor: Colors.BlueLight80, | ||
| contentColor: Colors.BlueLight40, | ||
| }, | ||
| Second: { | ||
| screens: ['Inner21', 'Inner22', 'Inner23'], | ||
| headerColor: Colors.GreenLight80, | ||
| contentColor: Colors.GreenLight40, | ||
| }, | ||
| Third: { | ||
| screens: ['Inner31', 'Inner32', 'Inner33'], | ||
| headerColor: Colors.YellowLight80, | ||
| contentColor: Colors.YellowLight40, | ||
| }, | ||
| }; | ||
|
|
||
| const createStack = (groupKey: keyof typeof screenGroups) => { | ||
| const { screens, headerColor, contentColor } = screenGroups[groupKey]; | ||
|
|
||
| return () => ( | ||
| <Stack.Navigator | ||
| screenOptions={{ | ||
| title: groupKey, | ||
| headerStyle: { backgroundColor: headerColor }, | ||
| contentStyle: { backgroundColor: contentColor }, | ||
| }} | ||
| > | ||
| {screens.map((screen, index) => { | ||
| const nextScreen = screens[index + 1]; | ||
| return ( | ||
| <Stack.Screen | ||
| key={screen} | ||
| name={screen} | ||
| component={createScreen(screen, nextScreen)} | ||
| /> | ||
| ); | ||
| })} | ||
| </Stack.Navigator> | ||
| ); | ||
| }; | ||
|
|
||
| const tabOptions = { | ||
| tabBarIcon: () => null, | ||
| }; | ||
|
|
||
| const RootTabs = () => ( | ||
| <Tab.Navigator screenOptions={{ headerShown: false }}> | ||
| <Tab.Screen name="First" component={createStack('First')} options={tabOptions} /> | ||
| <Tab.Screen name="Second" component={createStack('Second')} options={tabOptions} /> | ||
| <Tab.Screen name="Third" component={createStack('Third')} options={tabOptions} /> | ||
| </Tab.Navigator> | ||
| ); | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <SafeAreaProvider> | ||
| <NavigationContainer> | ||
| <RootTabs /> | ||
| </NavigationContainer> | ||
| </SafeAreaProvider> | ||
| ); | ||
| } | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| flex: 1, | ||
| alignItems: 'center', | ||
| justifyContent: 'center', | ||
| }, | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Reading this I have a problem with naming here. We call
onToolbarLayoutinrequestLayout. This clearly contradicts.Why do we call this callback in
requestLayout? Shouldn't it be called inonLayout?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.
By doing it this way, we call
onToolbarLayoutbefore the layout triggered by thisrequestLayoutcall happens. Is this intentional?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.
yes, in CustomAppBarLayout I'm calling
layoutexplicitly to make a correction asap, without any overhead regarding callingrequestLayoutThere 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.
b4247d5
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.
Okay. Can we add comment documenting this? That we call layout here, to ensure immediate frame update & prevent potentially invalid state being displayed before requested layout is executed.
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.
955d588