Skip to content

Commit

Permalink
chore: add hideKeyboardOnSwipe prop for Fabric (3) (#1433)
Browse files Browse the repository at this point in the history
* chore: move hideKeyboardOnSwipe prop to common section in RNSScreen
header

* chore: add hideKeyboardOnSwipe prop to codegen

* chore: make keyboard dismiss logic common

* chore: add hideKeyboardOnSwipe prop update for Fabric

* chore: add noop for Android

This prop is marked as iOS only

* chore: add `customAnimationOnSwipe` prop for Fabric (4) (#1434)

* chore: add customAnimationOnSwipe prop to codegen

* chore: move customAnimationOnSwipe prop to shared section in RNSScreen
interface

* refact: linter suggestion

* chore: add customAnimationOnSwipe update for Fabric

* chore: unify RNSScreenStackAnimator#animateTransition method

This is possible as customAnimationOnSwipe prop is now implemented on
Fabric

* chore: unify RNSScreenStack#gestureRecognizer should begin method

This is possible as customAnimationOnSwipe prop in now implemented on
Fabric

* chore: noop for Android

This prop is annotated as iOS only in docs

* chore: remove not needed difference between implementations

* chore: add `gestureResponseDistance` prop for Fabric (5) (#1442)

* chore: move gestureResponseDistance prop to shared section in RNSScreen
interface

* refact: linter suggestions

* chore: add gestureResponseDistanceProp to Codegen

* chore: add conversion methods for GestureResponseDistanceStruct

* refact: linter suggestion

* chore: add props update for Fabric

As there is no way for creating custom `equality operator` for custom
struct via codegen && such check (newProps != oldProps) would require
three "ands" I think it is easier and potentially cheaper to just assign
this (w/o surrounding if-check)

* chore: unify RNSScreenStack#gestureRecognizerShouldBegin method

* chore: move
RNSScreenStackView#isInGestureResponseDistance:gestureRecognizer: method
to common section

This is now possible, as `gestureResponseDistance` prop is available on
Fabric

* chore: add noop for Android

This prop is annotated as iOS only in docs

* chore: change GestureResponseDistance field type from int to float

* fix: merge artifact

* chore: add deafult value for gestureResponseDistance on JS side

It is still to be checked whether it is only place where this should be
added

* chore: unify RNSScreenStack#isInGestureResponseDistance:topScreen:
method

* chore: add `homeIndicatorHidden` & `activityState` props for Fabric (6) (#1443)

* chore: add homeIndicatorHidden prop to codegen

* chore: add prop update on Fabric

* chore: add noop for Android

This prop is iOS only

* chore: move `activityState` prop to common section in RNSScreen
interface

* chore: move activityState setter to common section in RNSScreenView impl

* refact: linter suggestion

* chore: make RNSScreenView#reactSuperview common & make it implement
RNSScreenContainerDelegate protocol

This hasn't been tested yet. However in any instance it crashes (as
    the protocol might be not implemented) we can just implement noops
for Fabric

* chore: move activityState to implemented section in codegen config files

* chore: make series of methods shared (see details)

* `RNSScreenView#notifyFinishTransitioning`
* `RNSScreen#notifyFinishTransitioning`
* `willMoveToParentViewController`
* `RNSScreenContainer#updateContainer`

These methods were coupled together.

* fix: handle activityState on Fabric

Default value for the prop (when it is not set) on Fabric is -1 instead
of nil (I believe we can not get nil from C++) thus this improved
condition should work for both archs.

* chore: add `preventNativeDismiss` prop for Fabric (7) (#1444)

* chore: move preventNativeDismiss prop to common section in RNSScreen
interface

* fix: merge artifact

* chore: add preventNativeDismiss prop to codegen

* chore: add preventNativeDismiss prop update

* fix: add noop for Android

* chore: unify business logic between archs (8) (#1446)

* chore: unify RNSScreen#vieDidLayoutSubviews

* chore: make RNSScreenStack#hitTest:withEvent: method shared

#1416 (comment)

* chore: make RNSScreenStackView#isScrollViewPanGestureRecongnizer & some
helper methods shared

#1416 (comment)

* chore: move backButtonInCustomView to shared sectionin
RNSScreenStackHeaderConfig.h

* chore: move backButtonInCustomView prop to implemented section in JS

* chore: update `backButtonInCustomView` for Fabric

* chore: unify
RNSScreenStackHeaderConfigView#willShowViewController:animated:withConfig

* refact: linter suggestion

* fix: RNSScreen viewDidLayoutSubviews

* chore: copy interfaces to android/src/paper directory

* fix: commit address in comment

It changed after I rebased
  • Loading branch information
kkafar authored May 13, 2022
1 parent bf05190 commit 2f977e1
Show file tree
Hide file tree
Showing 18 changed files with 263 additions and 180 deletions.
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);
}
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;

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

@end

#endif // RN_FABRIC_ENABLED
12 changes: 12 additions & 0 deletions ios/RNSConvert.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ + (RNSScreenReplaceAnimation)RNSScreenReplaceAnimationFromCppEquivalent:
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

0 comments on commit 2f977e1

Please sign in to comment.