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

chore: add replaceAnimation prop for Fabric (2) #1432

Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.swmansion.rnscreens

import com.facebook.react.bridge.JSApplicationIllegalArgumentException
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.MapBuilder
import com.facebook.react.module.annotations.ReactModule
import com.facebook.react.uimanager.ThemedReactContext
Expand Down Expand Up @@ -139,11 +140,21 @@ class ScreenViewManager : ViewGroupManager<Screen>(), RNSScreenManagerInterface<
view.nativeBackButtonDismissalEnabled = nativeBackButtonDismissalEnabled
}

// these props are not available on Android, however we must override their getters
// these props are not available on Android, however we must override their setters
override fun setFullScreenSwipeEnabled(view: Screen?, value: Boolean) = Unit

override fun setTransitionDuration(view: Screen?, value: Int) = Unit

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

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

override fun setGestureResponseDistance(view: Screen?, value: ReadableMap?) = Unit

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

override fun setPreventNativeDismiss(view: Screen?, value: Boolean) = 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 @@ -12,6 +12,7 @@
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;

Expand All @@ -22,9 +23,18 @@ public RNSScreenManagerDelegate(U viewManager) {
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "customAnimationOnSwipe":
mViewManager.setCustomAnimationOnSwipe(view, value == null ? false : (boolean) value);
break;
case "fullScreenSwipeEnabled":
mViewManager.setFullScreenSwipeEnabled(view, value == null ? false : (boolean) value);
break;
case "homeIndicatorHidden":
mViewManager.setHomeIndicatorHidden(view, value == null ? false : (boolean) value);
break;
case "preventNativeDismiss":
mViewManager.setPreventNativeDismiss(view, value == null ? false : (boolean) value);
break;
case "gestureEnabled":
mViewManager.setGestureEnabled(view, value == null ? true : (boolean) value);
break;
Expand All @@ -46,6 +56,9 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "statusBarTranslucent":
mViewManager.setStatusBarTranslucent(view, value == null ? false : (boolean) value);
break;
case "gestureResponseDistance":
mViewManager.setGestureResponseDistance(view, (ReadableMap) value);
break;
case "stackPresentation":
mViewManager.setStackPresentation(view, (String) value);
break;
Expand All @@ -58,6 +71,12 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "replaceAnimation":
mViewManager.setReplaceAnimation(view, (String) value);
break;
case "hideKeyboardOnSwipe":
mViewManager.setHideKeyboardOnSwipe(view, value == null ? false : (boolean) value);
break;
case "activityState":
mViewManager.setActivityState(view, value == null ? -1 : ((Double) value).intValue());
break;
case "navigationBarColor":
mViewManager.setNavigationBarColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
Expand All @@ -67,9 +86,6 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "nativeBackButtonDismissalEnabled":
mViewManager.setNativeBackButtonDismissalEnabled(view, value == null ? false : (boolean) value);
break;
case "activityState":
mViewManager.setActivityState(view, value == null ? -1 : ((Double) value).intValue());
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableMap;

public interface RNSScreenManagerInterface<T extends View> {
void setCustomAnimationOnSwipe(T view, boolean value);
void setFullScreenSwipeEnabled(T view, boolean value);
void setHomeIndicatorHidden(T view, boolean value);
void setPreventNativeDismiss(T view, boolean value);
void setGestureEnabled(T view, boolean value);
void setStatusBarColor(T view, @Nullable Integer value);
void setStatusBarHidden(T view, boolean value);
void setScreenOrientation(T view, @Nullable String value);
void setStatusBarAnimation(T view, @Nullable String value);
void setStatusBarStyle(T view, @Nullable String value);
void setStatusBarTranslucent(T view, boolean value);
void setGestureResponseDistance(T view, @Nullable ReadableMap value);
void setStackPresentation(T view, @Nullable String value);
void setStackAnimation(T view, @Nullable String value);
void setTransitionDuration(T view, int value);
void setReplaceAnimation(T view, @Nullable String value);
void setHideKeyboardOnSwipe(T view, boolean value);
void setActivityState(T view, int value);
void setNavigationBarColor(T view, @Nullable Integer value);
void setNavigationBarHidden(T view, boolean value);
void setNativeBackButtonDismissalEnabled(T view, boolean value);
void setActivityState(T view, int value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ public void setProperty(T view, String propName, @Nullable Object value) {
case "hideBackButton":
mViewManager.setHideBackButton(view, value == null ? false : (boolean) value);
break;
case "topInsetEnabled":
mViewManager.setTopInsetEnabled(view, value == null ? false : (boolean) value);
break;
case "backButtonInCustomView":
mViewManager.setBackButtonInCustomView(view, value == null ? false : (boolean) value);
break;
case "topInsetEnabled":
mViewManager.setTopInsetEnabled(view, value == null ? false : (boolean) value);
break;
default:
super.setProperty(view, propName, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ public interface RNSScreenStackHeaderConfigManagerInterface<T extends View> {
void setTitleColor(T view, @Nullable Integer value);
void setDisableBackButtonMenu(T view, boolean value);
void setHideBackButton(T view, boolean value);
void setTopInsetEnabled(T view, boolean value);
void setBackButtonInCustomView(T view, boolean value);
void setTopInsetEnabled(T view, boolean value);
}
6 changes: 6 additions & 0 deletions ios/RNSConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
+ (RNSScreenStackHeaderSubviewType)RNSScreenStackHeaderSubviewTypeFromCppEquivalent:
(facebook::react::RNSScreenStackHeaderSubviewType)subviewType;

+ (RNSScreenReplaceAnimation)RNSScreenReplaceAnimationFromCppEquivalent:
(facebook::react::RNSScreenReplaceAnimation)replaceAnimation;

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

@end

#endif // RN_FABRIC_ENABLED
23 changes: 23 additions & 0 deletions ios/RNSConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,29 @@ + (RNSScreenStackHeaderSubviewType)RNSScreenStackHeaderSubviewTypeFromCppEquival
return RNSScreenStackHeaderSubviewTypeBackButton;
}
}

+ (RNSScreenReplaceAnimation)RNSScreenReplaceAnimationFromCppEquivalent:
(facebook::react::RNSScreenReplaceAnimation)replaceAnimation
{
switch (replaceAnimation) {
case facebook::react::RNSScreenReplaceAnimation::Pop:
return RNSScreenReplaceAnimationPop;
case facebook::react::RNSScreenReplaceAnimation::Push:
return RNSScreenReplaceAnimationPush;
}
}

+ (NSDictionary *)gestureResponseDistanceDictFromCppStruct:
(const facebook::react::RNSScreenGestureResponseDistanceStruct &)gestureResponseDistance
{
return @{
@"start" : @(gestureResponseDistance.start),
@"end" : @(gestureResponseDistance.end),
@"top" : @(gestureResponseDistance.top),
@"bottom" : @(gestureResponseDistance.bottom),
};
}

@end

#endif // RN_FABRIC_ENABLED
20 changes: 9 additions & 11 deletions ios/RNSScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithView:(UIView *)view;
- (UIViewController *)findChildVCForConfigAndTrait:(RNSWindowTrait)trait includingModals:(BOOL)includingModals;
- (void)notifyFinishTransitioning;
#ifdef RN_FABRIC_ENABLED
- (void)setViewToSnapshot:(UIView *)snapshot;
- (void)resetViewToScreen;
#else
- (void)notifyFinishTransitioning;
#endif

@end
Expand All @@ -58,7 +57,13 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) RNSScreenReplaceAnimation replaceAnimation;
@property (nonatomic, retain) NSNumber *transitionDuration;
@property (nonatomic, readonly) BOOL dismissed;
@property (nonatomic) BOOL hideKeyboardOnSwipe;
@property (nonatomic) BOOL customAnimationOnSwipe;
@property (nonatomic) BOOL preventNativeDismiss;
@property (nonatomic, retain) RNSScreen *controller;
@property (nonatomic, copy) NSDictionary *gestureResponseDistance;
@property (nonatomic) int activityState;
@property (weak, nonatomic) UIView<RNSScreenContainerDelegate> *reactSuperview;

#if !TARGET_OS_TV
@property (nonatomic) RNSStatusBarStyle statusBarStyle;
Expand All @@ -70,7 +75,6 @@ NS_ASSUME_NONNULL_BEGIN

#ifdef RN_FABRIC_ENABLED
@property (weak, nonatomic) UIView *config;
@property (weak, nonatomic) UIView *reactSuperview;
#else
@property (nonatomic, copy) RCTDirectEventBlock onAppear;
@property (nonatomic, copy) RCTDirectEventBlock onDisappear;
Expand All @@ -79,15 +83,10 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) RCTDirectEventBlock onWillDisappear;
@property (nonatomic, copy) RCTDirectEventBlock onNativeDismissCancelled;
@property (nonatomic, copy) RCTDirectEventBlock onTransitionProgress;

@property (nonatomic) BOOL hideKeyboardOnSwipe;
@property (weak, nonatomic) UIView<RNSScreenContainerDelegate> *reactSuperview;
@property (nonatomic) int activityState;
@property (nonatomic) BOOL preventNativeDismiss;
@property (nonatomic) BOOL customAnimationOnSwipe;
@property (nonatomic, copy) NSDictionary *gestureResponseDistance;
#endif

- (void)notifyFinishTransitioning;

#ifdef RN_FABRIC_ENABLED
- (void)notifyWillAppear;
- (void)notifyWillDisappear;
Expand All @@ -96,7 +95,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)updateBounds;
- (void)notifyDismissedWithCount:(int)dismissCount;
#else
- (void)notifyFinishTransitioning;
- (void)notifyTransitionProgress:(double)progress closing:(BOOL)closing goingForward:(BOOL)goingForward;
#endif

Expand Down
Loading