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

fix: calculate values of useHeaderHeight natively #1802

Merged
merged 73 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from 72 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
ff823e3
Add first approach to read header height dynamically with Key-Value O…
tboba Jun 21, 2023
03872b1
Change Key-Value Observing method onto checking navbar height on view…
tboba Jun 21, 2023
0bccf30
Add event emitter for header change
tboba Jun 21, 2023
b6555e1
Change method naming to recalculateHeaderHeight
tboba Jun 26, 2023
5db75f8
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jun 26, 2023
a9be724
Add support for onHeaderHeightChange event on Fabric
tboba Jul 3, 2023
b99a56a
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 3, 2023
c0e962b
Fix problem with detecting height when header is set to translucent, …
tboba Jul 4, 2023
b02d9f6
Add support of dynamic header height calculating for android
tboba Jul 4, 2023
4b1d290
Refactor declaration of actionBarHeight
tboba Jul 4, 2023
1a3649d
Remove react-native-safe-area-context from NativeStackView, remove `g…
tboba Jul 5, 2023
5d18f8c
Remove lines desired for debugging in Test1072, add Test1802b
tboba Jul 5, 2023
1103609
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 5, 2023
1052c19
Revert wrong test number in FabricTestExample
tboba Jul 5, 2023
3b0ba3e
Add note about changing `useHeaderHeight` behavior to README.md in na…
tboba Jul 5, 2023
798e283
Move header height functionality to category, add support for modals
tboba Jul 6, 2023
335d4d2
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 7, 2023
fbf9b94
Refresh header height when user dismisses from modal
tboba Jul 7, 2023
e4cd3da
Add `dismissViewControllerAnimated` for dismissing modals, remove red…
tboba Jul 10, 2023
9f3097d
Add complete implementation for detecting modal height
tboba Jul 10, 2023
9bc05f5
Add `navigation.emit` declaration for `onHeaderHeightChange` in Nativ…
tboba Jul 10, 2023
45bb8f0
Add implementation of recalculating modal height on android
tboba Jul 11, 2023
df9c1fc
Rename event on android to `topHeaderHeightChange`
tboba Jul 11, 2023
dd4dff3
Revert removing getDefaultHeaderHeight, add possibility to use fallba…
tboba Jul 11, 2023
68a7719
Change parameter type of useHeaderHeight to boolean
tboba Jul 12, 2023
6272432
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 12, 2023
74fd49c
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 12, 2023
aa93bc0
Add final touches to code, remove debug console.log
tboba Jul 12, 2023
85ed428
Revert changes from Test1072 file
tboba Jul 12, 2023
d837743
Move declaration of onHeaderHeightChange event to the bottom in types…
tboba Jul 12, 2023
cbc474d
Disable calculating status bar height on TVOS
tboba Jul 12, 2023
abb9438
Apply changes from review, add `useAnimatedHeaderHeight` hook
tboba Jul 18, 2023
9ab4be6
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 18, 2023
595b37c
Make `calculateHeaderHeight` public, change documentation
tboba Jul 18, 2023
689bae4
Remove typo from RNSScreenStack
tboba Jul 18, 2023
39a5abf
Add caching of header height in NativeStackView
tboba Jul 18, 2023
d1175c4
Add Test1671 for FabricTestExample
tboba Jul 19, 2023
78a8152
Change `convertToDp` method to using PixelUtil class
tboba Jul 20, 2023
1f5d586
Change for and return statements in `hasAnyChildNavigators`, add #if …
tboba Jul 20, 2023
9b2e310
Remove redundant addSubview from RNSSCreenStack
tboba Jul 20, 2023
ae03a77
Remove isFullscreenModal and isTransparentModal from RNSScreen.h
tboba Jul 20, 2023
6798453
Change coalescing key from HeaderHeightChangeEvent
tboba Jul 20, 2023
3f7cc31
Change way of using useAnimatedHeaderHeight, change event behavior in…
tboba Jul 20, 2023
de25f47
Change Test1802 example
tboba Jul 20, 2023
d8cd697
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 20, 2023
3ab7372
Change RNScreensNavigationController to RNSNavigationController in `h…
tboba Jul 20, 2023
f2f3e6f
Add clarifying comment to endif
tboba Jul 21, 2023
2c9e6fb
Change type of header height value, add support for native driver on …
tboba Jul 21, 2023
5c1fe68
Change way of setting new height in onHeaderHeightChange, add caching…
tboba Jul 21, 2023
9fa18c5
Create useReanimatedHeaderHeight hook for Reanimated support
tboba Jul 24, 2023
6654386
Fix grammar
tboba Jul 24, 2023
d3428b7
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 25, 2023
a68658b
Replace let into ref, add note about `useReanimatedHeaderHeight` to R…
tboba Jul 27, 2023
6b23ba4
Remove *.plist from gitignore
tboba Jul 27, 2023
f746d21
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Jul 28, 2023
9030deb
Change React Native's StatusBar to `statusBarStyle` option from Screen
tboba Jul 28, 2023
970dfca
Apply changes in documentation
tboba Jul 28, 2023
db7b505
Change `newHeight` to `height` / `headerHeight`
tboba Aug 2, 2023
bb80aef
Change `event` to `events` in ios
tboba Aug 2, 2023
eae889e
Add caching for ReanimatedNativeStackScreen
tboba Aug 2, 2023
94e5290
Remove `wasModalPresented` from `dismissViewControllerAnimated`
tboba Aug 10, 2023
d2622c4
Rename `hasAnyChildNavigators` to `hasNestedStack`
tboba Aug 10, 2023
9557ec6
Add super to `viewDidLayoutSubviews`
tboba Aug 10, 2023
d8f0dab
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Aug 16, 2023
2edab99
Wrap animatedHeaderHeight with React.useRef for remembering previous …
tboba Aug 16, 2023
271a437
Remove unnecessary calls of `calculateHeaderHeightIsModal` on modal d…
tboba Aug 16, 2023
246d3a5
Remove leftovers from Android
tboba Aug 21, 2023
a7d90a8
add case for `UIModalPresentationOverCurrentContext` to `isTransparen…
tboba Aug 21, 2023
fe776ca
Change `RNScreensNavigationController` to `RNSNavigationController` i…
tboba Aug 21, 2023
3c9c0fb
Rename `HeaderChangeEvent` to `HeaderHeightChangeEvent` in JS side
tboba Aug 21, 2023
aabfc7e
Refactorize `calculateHeaderHeightIsModal`, change `hasNestedStack` d…
tboba Aug 21, 2023
6a0e88b
fix(Android): Fix reporting invalid status bar height on Android (#1873)
tboba Aug 21, 2023
d893498
Merge branch 'main' into @tboba/dynamic-use-header-height
tboba Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FabricTestExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ import Test1473 from './src/Test1473';
import Test1476 from './src/Test1476';
import Test1646 from './src/Test1646';
import Test1649 from './src/Test1649';
import Test1671 from './src/Test1671';
import Test1683 from './src/Test1683';
import Test1726 from './src/Test1726';
import Test1802 from './src/Test1802';
import Test1844 from './src/Test1844';
import Test1864 from './src/Test1864';

Expand Down
74 changes: 74 additions & 0 deletions FabricTestExample/src/Test1671.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
import { View } from 'react-native';
import {
useHeaderHeight,
createNativeStackNavigator,
} from 'react-native-screens/native-stack';
import { NavigationContainer } from '@react-navigation/native';

const App = () => {
const backgroundStyle = {
backgroundColor: '#fafffe', // isDarkMode ? Colors.darker : Colors.lighter,
};

return (
<View
style={[
backgroundStyle,
{
flex: 1,
},
]}>
<View
style={{
flex: 1,
height: '100%',
}}>
<Navigation />
</View>
</View>
);
};

const List = () => {
const headerHeight = useHeaderHeight();

return (
<View style={{ flex: 1, backgroundColor: '#00fffa' }}>
<View
style={{
backgroundColor: '#fffa00',
position: 'absolute',
top: headerHeight,
width: 200,
height: 100,
}}
/>
</View>
);
};

const Stack = createNativeStackNavigator();

const Navigation = () => {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
fullScreenSwipeEnabled: true,
stackAnimation: 'fade_from_bottom',
customAnimationOnSwipe: true,
// headerLargeTitle: true,
headerTranslucent: true,
}}>
<Stack.Screen
name="Header"
component={List}
options={{ statusBarStyle: 'dark' }}
/>
</Stack.Navigator>
</NavigationContainer>
);
};

export default App;
174 changes: 174 additions & 0 deletions FabricTestExample/src/Test1802.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import React from 'react';
import { Dimensions, Image, StyleSheet, Text, View } from 'react-native';
import { NavigationContainer, ParamListBase } from '@react-navigation/native';

import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';

// Uncomment these lines if you want to test useAnimatedHeaderHeight.
import { Animated } from 'react-native';
import { useAnimatedHeaderHeight } from 'react-native-screens/native-stack';

// Uncomment these lines if you want to test useReanimatedHeaderHeight.
// import Animated from 'react-native-reanimated';
// import { useReanimatedHeaderHeight } from 'react-native-screens/reanimated';

import {
GestureHandlerRootView,
ScrollView,
State,
TapGestureHandler,
} from 'react-native-gesture-handler';
import { ReanimatedScreenProvider } from 'react-native-screens/reanimated';
import { FullWindowOverlay } from 'react-native-screens';

const Stack = createNativeStackNavigator();

function ExampleScreen() {
const headerHeight = useAnimatedHeaderHeight();
// const headerHeight = useReanimatedHeaderHeight();
tboba marked this conversation as resolved.
Show resolved Hide resolved

return (
<FullWindowOverlay>
<Animated.View
style={{
display: 'flex',
justifyContent: 'flex-end',
alignItems: 'center',

backgroundColor: 'red',
width: '100%',
opacity: 0.5,
height: 60,
zIndex: 1,
transform: [
{
translateY: headerHeight,
},
],
}}>
<Text>I'm a header!</Text>
</Animated.View>
</FullWindowOverlay>
);
}

const enablePerformanceTests = false;

function First({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
return (
<ScrollView contentInsetAdjustmentBehavior="automatic">
<ExampleScreen />
<Post onPress={() => navigation.navigate('Second')} />
<Post onPress={() => navigation.navigate('Second')} />
<Post onPress={() => navigation.navigate('Second')} />
{
// Generate 1000 posts for performance testing.
enablePerformanceTests &&
Array(1000)
.fill(0)
.map(_ => <Post onPress={() => navigation.navigate('Second')} />)
}
</ScrollView>
);
}

function Second() {
return (
<ScrollView>
<ExampleScreen />
<Text style={styles.subTitle}>
Use swipe back gesture to go back (iOS only)
</Text>
<Post />
</ScrollView>
);
}

export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<ReanimatedScreenProvider>
<NavigationContainer>
<Stack.Navigator
screenOptions={{
fullScreenSwipeEnabled: true,
stackAnimation: 'fade_from_bottom',
customAnimationOnSwipe: true,
headerLargeTitle: true,
// headerTranslucent: true,
}}>
<Stack.Screen name="First" component={First} />
<Stack.Screen name="Second" component={Second} />
</Stack.Navigator>
</NavigationContainer>
</ReanimatedScreenProvider>
</GestureHandlerRootView>
);
}

// components

function Post({ onPress }: { onPress?: () => void }) {
const [width] = React.useState(Math.round(Dimensions.get('screen').width));

return (
<TapGestureHandler
onHandlerStateChange={e =>
e.nativeEvent.oldState === State.ACTIVE && onPress?.()
}>
<View style={styles.post}>
<Text style={styles.title}>Post</Text>
<ScrollView horizontal>{generatePhotos(4, width, 400)}</ScrollView>
<Text style={styles.caption}>Scroll right for more photos</Text>
</View>
</TapGestureHandler>
);
}

// helpers
function generatePhotos(
amount: number,
width: number,
height: number,
): JSX.Element[] {
const startFrom = Math.floor(Math.random() * 20) + 10;
return Array.from({ length: amount }, (_, index) => {
const uri = `https://picsum.photos/id/${
startFrom + index
}/${width}/${height}`;
return <Image style={{ width, height }} key={uri} source={{ uri }} />;
});
}

const styles = StyleSheet.create({
title: {
fontWeight: 'bold',
fontSize: 32,
marginBottom: 8,
marginLeft: 8,
},
subTitle: {
fontSize: 18,
marginVertical: 16,
textAlign: 'center',
},
caption: {
textAlign: 'center',
marginTop: 4,
},
post: {
borderColor: '#ccc',
borderTopWidth: 1,
borderBottomWidth: 1,
paddingVertical: 10,
marginBottom: 16,
backgroundColor: 'white',
},
});
2 changes: 2 additions & 0 deletions TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ import Test1509 from './src/Test1509';
import Test1539 from './src/Test1539';
import Test1646 from './src/Test1646';
import Test1649 from './src/Test1649';
import Test1671 from './src/Test1671';
import Test1683 from './src/Test1683';
import Test1726 from './src/Test1726';
import Test1791 from './src/Test1791';
import Test1802 from './src/Test1802';
import Test1844 from './src/Test1844';
import Test1864 from './src/Test1864';

Expand Down
74 changes: 74 additions & 0 deletions TestsExample/src/Test1671.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react';
tboba marked this conversation as resolved.
Show resolved Hide resolved
import { View } from 'react-native';
import {
useHeaderHeight,
createNativeStackNavigator,
} from 'react-native-screens/native-stack';
import { NavigationContainer } from '@react-navigation/native';

const App = () => {
const backgroundStyle = {
backgroundColor: '#fafffe', // isDarkMode ? Colors.darker : Colors.lighter,
};

return (
<View
style={[
backgroundStyle,
{
flex: 1,
},
]}>
<View
style={{
flex: 1,
height: '100%',
}}>
<Navigation />
</View>
</View>
);
};

const List = () => {
const headerHeight = useHeaderHeight();

return (
<View style={{ flex: 1, backgroundColor: '#00fffa' }}>
<View
style={{
backgroundColor: '#fffa00',
position: 'absolute',
top: headerHeight,
width: 200,
height: 100,
}}
/>
</View>
);
};

const Stack = createNativeStackNavigator();

const Navigation = () => {
return (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
fullScreenSwipeEnabled: true,
stackAnimation: 'fade_from_bottom',
customAnimationOnSwipe: true,
// headerLargeTitle: true,
headerTranslucent: true,
}}>
<Stack.Screen
name="Header"
component={List}
options={{ statusBarStyle: 'dark' }}
/>
</Stack.Navigator>
</NavigationContainer>
);
};

export default App;
Loading