Skip to content

Commit fd72578

Browse files
authored
fix: make header subviews subscribe to transition (#820)
Added change to ScreenStackHeaderConfig.java to expose the Toolbar, of which the ScreenStackHeaderSubviews are the children. It is needed since the Toolbar is not a child of Screen in the view hierarchy, therefore its children are not subscribed to the transition by default. Then, in the prepareOutTransition, we add a check for ScreenStackHeaderConfig and apply the transition to the children of its Toolbar making them stay on the screen for during the transition of going back.
1 parent 5f31cd8 commit fd72578

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

TestsExample/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Test748 from './src/Test748';
2929
import Test750 from './src/Test750';
3030
import Test765 from './src/Test765';
3131
import Test780 from './src/Test780';
32+
import Test817 from './src/Test817';
3233
import Test831 from './src/Test831';
3334

3435
enableScreens();

TestsExample/src/Test817.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* eslint-disable react/display-name */
2+
import React from "react";
3+
import { View, Text, Button } from "react-native";
4+
5+
import { NavigationContainer, ParamListBase } from "@react-navigation/native";
6+
import { createNativeStackNavigator, NativeStackNavigationProp } from "react-native-screens/native-stack";
7+
8+
const Stack = createNativeStackNavigator();
9+
10+
const App = (): JSX.Element => {
11+
return (
12+
<NavigationContainer>
13+
<Stack.Navigator
14+
screenOptions={{
15+
stackAnimation: "slide_from_right",
16+
}}
17+
>
18+
<Stack.Screen
19+
name="Home"
20+
component={Home}
21+
/>
22+
<Stack.Screen
23+
name="Notifications"
24+
component={Notifications}
25+
options={{
26+
headerCenter: () => <Text>Hello!</Text>,
27+
headerRight: () => <Text>Some other text</Text>,
28+
}}
29+
/>
30+
</Stack.Navigator>
31+
</NavigationContainer>
32+
);
33+
};
34+
35+
function Home({navigation}: {navigation: NativeStackNavigationProp<ParamListBase>}) {
36+
return (
37+
<View>
38+
<Button
39+
title="Navigate"
40+
onPress={() => navigation.navigate("Notifications")}
41+
/>
42+
</View>
43+
)
44+
}
45+
46+
function Notifications() {
47+
return <View />;
48+
}
49+
50+
export default App;

android/src/main/java/com/swmansion/rnscreens/ScreenStackHeaderConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ private void maybeUpdate() {
318318
}
319319
}
320320

321+
public Toolbar getToolbar() {
322+
return mToolbar;
323+
}
324+
321325
public ScreenStackHeaderSubview getConfigSubview(int index) {
322326
return mConfigSubviews.get(index);
323327
}

android/src/main/java/com/swmansion/rnscreens/ScreenStackViewManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ private void startTransitionRecursive(ViewGroup parent) {
4444
for (int i = 0, size = parent.getChildCount(); i < size; i++) {
4545
View child = parent.getChildAt(i);
4646
parent.startViewTransition(child);
47+
if (child instanceof ScreenStackHeaderConfig) {
48+
// we want to start transition on children of the toolbar too,
49+
// which is not a child of ScreenStackHeaderConfig
50+
startTransitionRecursive(((ScreenStackHeaderConfig) child).getToolbar());
51+
}
4752
if (child instanceof ViewGroup) {
4853
startTransitionRecursive((ViewGroup) child);
4954
}

0 commit comments

Comments
 (0)