-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into fix-random-freezes-on…
…-ios-when-using-modal
- Loading branch information
Showing
25 changed files
with
686 additions
and
239 deletions.
There are no files selected for viewing
This file contains 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 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 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,87 @@ | ||
import React from 'react'; | ||
import { NavigationContainer } from '@react-navigation/native'; | ||
import { View, StyleSheet, Button } from 'react-native'; | ||
import { GestureHandlerRootView } from 'react-native-gesture-handler'; | ||
import { | ||
NativeStackNavigationProp, | ||
createNativeStackNavigator, | ||
} from 'react-native-screens/native-stack' | ||
import { GestureDetectorProvider } from 'react-native-screens/gesture-handler'; | ||
|
||
type StackParamList = { | ||
ScreenA: undefined; | ||
ScreenB: undefined; | ||
ScreenC: undefined; | ||
}; | ||
|
||
interface MainScreenProps { | ||
navigation: NativeStackNavigationProp<StackParamList, 'ScreenA'>; | ||
} | ||
|
||
const MainScreen = ({ navigation }: MainScreenProps): JSX.Element => ( | ||
<View style={{ ...styles.container, backgroundColor: 'moccasin' }}> | ||
<Button | ||
title="Go ScreenB" | ||
onPress={() => { | ||
navigation.navigate('ScreenB'); | ||
}} | ||
/> | ||
<Button onPress={() => navigation.pop()} title="🔙 Back to Examples" /> | ||
</View> | ||
); | ||
|
||
interface ScreenBProps { | ||
navigation: NativeStackNavigationProp<StackParamList, 'ScreenB'>; | ||
} | ||
|
||
const ScreenB = ({ navigation }: ScreenBProps): JSX.Element => ( | ||
<View style={{ ...styles.container, backgroundColor: 'thistle' }}> | ||
<Button title="Go ScreenC" onPress={() => navigation.navigate('ScreenC')} /> | ||
<Button title="Go back" onPress={() => navigation.goBack()} /> | ||
</View> | ||
); | ||
|
||
interface ScreenCProps { | ||
navigation: NativeStackNavigationProp<StackParamList, 'ScreenC'>; | ||
} | ||
|
||
const ScreenC = ({ navigation }: ScreenCProps): JSX.Element => ( | ||
<View style={{ ...styles.container, backgroundColor: 'blue' }}> | ||
<Button title="Go back" onPress={() => navigation.goBack()} /> | ||
</View> | ||
); | ||
|
||
const Stack = createNativeStackNavigator<StackParamList>(); | ||
|
||
const App = (): JSX.Element => ( | ||
<GestureHandlerRootView style={{ flex: 1 }}> | ||
<NavigationContainer> | ||
<GestureDetectorProvider> | ||
<Stack.Navigator | ||
screenOptions={{ | ||
headerBackVisible: false, | ||
animation: 'none', | ||
}}> | ||
<Stack.Screen name="ScreenA" component={MainScreen} /> | ||
<Stack.Screen | ||
name="ScreenB" | ||
component={ScreenB} | ||
options={{ | ||
goBackGesture: 'twoDimensionalSwipe', | ||
}} | ||
/> | ||
<Stack.Screen name="ScreenC" component={ScreenC} /> | ||
</Stack.Navigator> | ||
</GestureDetectorProvider> | ||
</NavigationContainer> | ||
</GestureHandlerRootView> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
paddingTop: 10, | ||
}, | ||
}); | ||
|
||
export default App; |
This file contains 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 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 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,12 @@ | ||
#import <UIKit/UIKit.h> | ||
#import "RNSScreenStackAnimator.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RNSPercentDrivenInteractiveTransition : UIPercentDrivenInteractiveTransition | ||
|
||
@property (nonatomic, nullable) RNSScreenStackAnimator *animationController; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains 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,69 @@ | ||
#import "RNSPercentDrivenInteractiveTransition.h" | ||
|
||
@implementation RNSPercentDrivenInteractiveTransition { | ||
RNSScreenStackAnimator *_animationController; | ||
} | ||
|
||
#pragma mark - UIViewControllerInteractiveTransitioning | ||
|
||
- (void)startInteractiveTransition:(id<UIViewControllerContextTransitioning>)transitionContext | ||
{ | ||
[super startInteractiveTransition:transitionContext]; | ||
} | ||
|
||
#pragma mark - UIPercentDrivenInteractiveTransition | ||
|
||
// `updateInteractiveTransition`, `finishInteractiveTransition`, | ||
// `cancelInteractiveTransition` are forwared by superclass to | ||
// corresponding methods in transition context. In case | ||
// of "classical CA driven animations", such as UIView animation blocks | ||
// or direct utilization of CoreAnimation API, context drives the animation, | ||
// however in case of UIViewPropertyAnimator it does not. We need | ||
// to drive animation manually and this is exactly what happens below. | ||
|
||
- (void)updateInteractiveTransition:(CGFloat)percentComplete | ||
{ | ||
if (_animationController != nil) { | ||
[_animationController.inFlightAnimator setFractionComplete:percentComplete]; | ||
} | ||
[super updateInteractiveTransition:percentComplete]; | ||
} | ||
|
||
- (void)finishInteractiveTransition | ||
{ | ||
[self finalizeInteractiveTransitionWithAnimationWasCancelled:NO]; | ||
[super finishInteractiveTransition]; | ||
} | ||
|
||
- (void)cancelInteractiveTransition | ||
{ | ||
[self finalizeInteractiveTransitionWithAnimationWasCancelled:YES]; | ||
[super cancelInteractiveTransition]; | ||
} | ||
|
||
#pragma mark - Helpers | ||
|
||
- (void)finalizeInteractiveTransitionWithAnimationWasCancelled:(BOOL)cancelled | ||
{ | ||
if (_animationController == nil) { | ||
return; | ||
} | ||
|
||
UIViewPropertyAnimator *_Nullable animator = _animationController.inFlightAnimator; | ||
if (animator == nil) { | ||
return; | ||
} | ||
|
||
BOOL shouldReverseAnimation = cancelled; | ||
|
||
id<UITimingCurveProvider> timingParams = [_animationController timingParamsForAnimationCompletion]; | ||
|
||
[animator pauseAnimation]; | ||
[animator setReversed:shouldReverseAnimation]; | ||
[animator continueAnimationWithTimingParameters:timingParams durationFactor:(1 - animator.fractionComplete)]; | ||
|
||
// System retains it & we don't need it anymore. | ||
_animationController = nil; | ||
} | ||
|
||
@end |
This file contains 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 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 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.