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

feat: missing Screen prop: swipeDirection #1461

Merged
merged 8 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
39 changes: 39 additions & 0 deletions FabricTestExample/src/Test1260.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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';

const Stack = createNativeStackNavigator();

export default function App() {
return (
<NavigationContainer>
<Stack.Navigator screenOptions={{
swipeDirection: 'vertical',
}}>
<Stack.Screen name="First" component={First} />
<Stack.Screen
name="Second"
component={Second}
/>
</Stack.Navigator>
</NavigationContainer>
);
}

function First({navigation}: {navigation: NativeStackNavigationProp<ParamListBase>}) {
return (
<View style={{flex: 1, backgroundColor: 'red'}}>
<Button title="Tap me for second screen" onPress={() => navigation.navigate('Second')} />
</View>

);
}

function Second({navigation}: {navigation: NativeStackNavigationProp<ParamListBase>}) {
return (
<View style={{flex: 1, backgroundColor: 'blue'}}>
<Button title="Tap me for second screen" onPress={() => navigation.navigate('First')} />
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class ScreenViewManager : ViewGroupManager<Screen>(), RNSScreenManagerInterface<

override fun setPreventNativeDismiss(view: Screen?, value: Boolean) = Unit

override fun setSwipeDirection(view: Screen?, value: String?) = Unit

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
val map: MutableMap<String, Any> = MapBuilder.of(
ScreenDismissedEvent.EVENT_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "replaceAnimation":
mViewManager.setReplaceAnimation(view, (String) value);
break;
case "swipeDirection":
mViewManager.setSwipeDirection(view, (String) value);
break;
case "hideKeyboardOnSwipe":
mViewManager.setHideKeyboardOnSwipe(view, value == null ? false : (boolean) value);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface RNSScreenManagerInterface<T extends View> {
void setStackAnimation(T view, @Nullable String value);
void setTransitionDuration(T view, int value);
void setReplaceAnimation(T view, @Nullable String value);
void setSwipeDirection(T view, @Nullable String value);
void setHideKeyboardOnSwipe(T view, boolean value);
void setActivityState(T view, int value);
void setNavigationBarColor(T view, @Nullable Integer value);
Expand Down
3 changes: 3 additions & 0 deletions ios/RNSConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
+ (RNSScreenReplaceAnimation)RNSScreenReplaceAnimationFromCppEquivalent:
(facebook::react::RNSScreenReplaceAnimation)replaceAnimation;

+ (RNSScreenSwipeDirection)RNSScreenSwipeDirectionFromCppEquivalent:
(facebook::react::RNSScreenSwipeDirection)swipeDirection;

+ (NSDictionary *)gestureResponseDistanceDictFromCppStruct:
(const facebook::react::RNSScreenGestureResponseDistanceStruct &)gestureResponseDistance;

Expand Down
11 changes: 11 additions & 0 deletions ios/RNSConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ + (RNSScreenReplaceAnimation)RNSScreenReplaceAnimationFromCppEquivalent:
}
}

+ (RNSScreenSwipeDirection)RNSScreenSwipeDirectionFromCppEquivalent:
(facebook::react::RNSScreenSwipeDirection)swipeDirection
{
switch (swipeDirection) {
case facebook::react::RNSScreenSwipeDirection::Horizontal:
return RNSScreenSwipeDirectionHorizontal;
case facebook::react::RNSScreenSwipeDirection::Vertical:
return RNSScreenSwipeDirectionVertical;
}
}

+ (NSDictionary *)gestureResponseDistanceDictFromCppStruct:
(const facebook::react::RNSScreenGestureResponseDistanceStruct &)gestureResponseDistance
{
Expand Down
4 changes: 3 additions & 1 deletion ios/RNSScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ - (void)updateProps:(facebook::react::Props::Shared const &)props

[self setActivityStateOrNil:[NSNumber numberWithInt:newScreenProps.activityState]];

[self setSwipeDirection:[RNSConvert RNSScreenSwipeDirectionFromCppEquivalent:newScreenProps.swipeDirection]];

#if !TARGET_OS_TV
if (newScreenProps.statusBarHidden != oldScreenProps.statusBarHidden) {
[self setStatusBarHidden:newScreenProps.statusBarHidden];
Expand Down Expand Up @@ -508,7 +510,7 @@ - (void)updateProps:(facebook::react::Props::Shared const &)props
if (newScreenProps.replaceAnimation != oldScreenProps.replaceAnimation) {
[self setReplaceAnimation:[RNSConvert RNSScreenReplaceAnimationFromCppEquivalent:newScreenProps.replaceAnimation]];
}

[super updateProps:props oldProps:oldProps];
}

Expand Down
36 changes: 17 additions & 19 deletions ios/RNSScreenStack.mm
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,9 @@ - (BOOL)isInGestureResponseDistance:(UIGestureRecognizer *)gestureRecognizer top
if (isRTL) {
x = _controller.view.frame.size.width - x;
}

// see: https://github.com/software-mansion/react-native-screens/pull/1442/commits/74d4bae321875d8305ad021b3d448ebf713e7d56

// see:
// https://github.com/software-mansion/react-native-screens/pull/1442/commits/74d4bae321875d8305ad021b3d448ebf713e7d56
// this prop is always default initialized so we do not expect any nils
float start = [gestureResponseDistanceValues[@"start"] floatValue];
float end = [gestureResponseDistanceValues[@"end"] floatValue];
Expand All @@ -761,10 +762,7 @@ - (BOOL)isInGestureResponseDistance:(UIGestureRecognizer *)gestureRecognizer top

// we check if any of the constraints are violated and return NO if so
return !(
(start != -1 && x < start) ||
(end != -1 && x > end) ||
(top != -1 && y < top) ||
(bottom != -1 && y > bottom));
(start != -1 && x < start) || (end != -1 && x > end) || (top != -1 && y < top) || (bottom != -1 && y > bottom));
}

// By default, the header buttons that are not inside the native hit area
Expand Down Expand Up @@ -808,6 +806,19 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
return [self isScrollViewPanGestureRecognizer:otherGestureRecognizer];
}

- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:
(id<UIViewControllerAnimatedTransitioning>)animationController
{
return _interactionController;
}

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:
(id<UIViewControllerAnimatedTransitioning>)animator
{
return _interactionController;
}

#ifdef RN_FABRIC_ENABLED
#pragma mark - Fabric specific

Expand Down Expand Up @@ -943,19 +954,6 @@ - (void)invalidate
[_controller willMoveToParentViewController:nil];
[_controller removeFromParentViewController];
}

- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
interactionControllerForAnimationController:
(id<UIViewControllerAnimatedTransitioning>)animationController
{
return _interactionController;
}

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:
(id<UIViewControllerAnimatedTransitioning>)animator
{
return _interactionController;
}
#endif // RN_FABRIC_ENABLED

@end
Expand Down
2 changes: 1 addition & 1 deletion ios/RNSScreenStackHeaderConfig.mm
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ - (void)updateProps:(facebook::react::Props::Shared const &)props
_translucent = newScreenProps.translucent;
needsNavigationControllerLayout = YES;
}

if (newScreenProps.backButtonInCustomView != _backButtonInCustomView) {
[self setBackButtonInCustomView:newScreenProps.backButtonInCustomView];
}
Expand Down
3 changes: 3 additions & 0 deletions src/fabric/ScreenNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type StackAnimation =
| 'slide_from_bottom'
| 'fade_from_bottom';

type SwipeDirection = 'vertical' | 'horizontal';

type ReplaceAnimation = 'pop' | 'push';

export type NativeProps = $ReadOnly<{|
Expand All @@ -71,6 +73,7 @@ export type NativeProps = $ReadOnly<{|
stackAnimation?: WithDefault<StackAnimation, 'default'>,
transitionDuration?: WithDefault<Int32, 350>,
replaceAnimation?: WithDefault<ReplaceAnimation, 'pop'>,
swipeDirection?: WithDefault<SwipeDirection, 'horizontal'>,
hideKeyboardOnSwipe?: boolean,
activityState?: WithDefault<Int32, -1>,
// TODO: implement these props on iOS
Expand Down