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: Adds dispatch for hiding header #1153

Merged
merged 12 commits into from
Oct 8, 2021
1 change: 1 addition & 0 deletions TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Test1036 from './src/Test1036';
import Test1072 from './src/Test1072';
import Test1084 from './src/Test1084';
import Test1096 from './src/Test1096';
import Test1153 from './src/Test1153';

export default function App() {
return (
Expand Down
87 changes: 87 additions & 0 deletions TestsExample/src/Test1153.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as React from 'react';
import {Button, View} from 'react-native';
import {NavigationContainer, ParamListBase} from '@react-navigation/native';
import {
createNativeStackNavigator,
NativeStackNavigationProp,
} from 'react-native-screens/native-stack';
import {SafeAreaView} from 'react-native-safe-area-context';
import { ScrollView } from 'react-native-gesture-handler';

const Stack = createNativeStackNavigator();

export default function App() {
return (
<View style={{flex: 1}}>
<NavigationContainer>
<Stack.Navigator screenOptions={{gestureEnabled: true}}>
<Stack.Screen
name="First"
component={First}
options={{
gestureEnabled: true,
headerTranslucent: true,
searchBar: {
placeholder: 'Interesting places...',
obscureBackground: false,
hideWhenScrolling: false,
},
}}
/>
<Stack.Screen
name="Second"
component={Second}
options={{
headerShown: false,
}}
/>
</Stack.Navigator>
</NavigationContainer>
</View>
);
}

function First({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
return (
<ScrollView
style={{
backgroundColor: '#000',
flex: 1,
}}
contentInsetAdjustmentBehavior="automatic">
<SafeAreaView>
<Button
title="Tap me for second screen"
onPress={() => {
navigation.push('Second');
}}
/>
</SafeAreaView>
</ScrollView>
);
}

function Second({
navigation,
}: {
navigation: NativeStackNavigationProp<ParamListBase>;
}) {
return (
<View style={{backgroundColor: '#777', flex: 1, justifyContent: 'center'}}>
<Button
title="Tap me to go back"
onPress={() => {
navigation.pop();
}}
/>
<Button
title="Open this screen again"
onPress={() => navigation.push('Second')}
/>
</View>
);
}
23 changes: 23 additions & 0 deletions ios/RNSScreen.m
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,29 @@ - (void)viewWillAppear:(BOOL)animated
_shouldNotify = NO;
}

#if !TARGET_OS_TV
NSUInteger currentIndex = [self.navigationController.viewControllers indexOfObject:self];
Ubax marked this conversation as resolved.
Show resolved Hide resolved

if (@available(iOS 11.0, *)) {
if (currentIndex > 0 && [self.view.reactSubviews[0] isKindOfClass:[RNSScreenStackHeaderConfig class]]) {
UINavigationItem *prevNavigationItem =
[self.navigationController.viewControllers objectAtIndex:currentIndex - 1].navigationItem;
RNSScreenStackHeaderConfig *config = ((RNSScreenStackHeaderConfig *)self.view.reactSubviews[0]);

BOOL wasSearchBarActiveActive = prevNavigationItem.searchController.active;
Ubax marked this conversation as resolved.
Show resolved Hide resolved
BOOL shouldHideHeader = config.hide;

if (wasSearchBarActiveActive && shouldHideHeader) {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
// We need to hide header beacuse if searchbar was active, then iOS would show default header for some reason
Ubax marked this conversation as resolved.
Show resolved Hide resolved
[self.navigationController setNavigationBarHidden:YES animated:NO];
});
}
}
}
#endif

// as per documentation of these methods
_goingForward = [self isBeingPresented] || [self isMovingToParentViewController];

Expand Down