Created
June 3, 2024 08:57
-
-
Save sriharsha-y/1e847547c42254b8b33421d4edcc24f9 to your computer and use it in GitHub Desktop.
Patch for reac-native-pager-view v6.3.1
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
diff --git a/android/Android.mk b/android/Android.mk | |
deleted file mode 100644 | |
index d2ff7090f9ffc36bf3b123b82b9aeccf6deba665..0000000000000000000000000000000000000000 | |
--- a/android/Android.mk | |
+++ /dev/null | |
@@ -1,45 +0,0 @@ | |
-THIS_DIR := $(call my-dir) | |
- | |
-include $(REACT_ANDROID_DIR)/Android-prebuilt.mk | |
- | |
-include ${GENERATED_SRC_DIR}/codegen/jni/Android.mk | |
- | |
-include $(CLEAR_VARS) | |
- | |
-LOCAL_PATH := $(THIS_DIR) | |
- | |
-# Define the library name here. | |
-LOCAL_MODULE := ${CODEGEN_MODULE_NAME}_registration | |
- | |
-LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) | |
- | |
-LOCAL_SHARED_LIBRARIES := \ | |
- libfabricjni \ | |
- libfbjni \ | |
- libglog \ | |
- libjsi \ | |
- libreact_codegen_rncore \ | |
- libreact_codegen_${CODEGEN_MODULE_NAME} \ | |
- libreact_debug \ | |
- libreact_nativemodule_core \ | |
- libreact_render_componentregistry \ | |
- libreact_render_core \ | |
- libreact_render_debug \ | |
- libreact_render_graphics \ | |
- librrc_view \ | |
- libruntimeexecutor \ | |
- libturbomodulejsijni \ | |
- libyoga | |
- | |
-ifneq ($(filter $(call modules-get-list),folly_runtime),) | |
- LOCAL_SHARED_LIBRARIES += libfolly_runtime # since [email protected] | |
-else | |
- LOCAL_SHARED_LIBRARIES += libfolly_futures libfolly_json # [email protected] | |
-endif | |
- | |
-LOCAL_CFLAGS := \ | |
- -DLOG_TAG=\"ReactNative\" \ | |
- -DCODEGEN_COMPONENT_DESCRIPTOR_H="<react/renderer/components/${CODEGEN_MODULE_NAME}/ComponentDescriptors.h>" | |
-LOCAL_CFLAGS += -fexceptions -frtti -std=c++17 -Wall | |
- | |
-include $(BUILD_SHARED_LIBRARY) | |
\ No newline at end of file | |
diff --git a/android/build.gradle b/android/build.gradle | |
index 8554e7b9d103d6058b15870c02a3fef583b5b570..6713357383d62ea5ac4ad232bc64ae7378341ef4 100644 | |
--- a/android/build.gradle | |
+++ b/android/build.gradle | |
@@ -92,34 +92,6 @@ android { | |
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() | |
buildConfigField "String", "CODEGEN_MODULE_REGISTRATION", (isNewArchitectureEnabled() && registrationCompat ? "\"${codegenViewModuleName}_registration\"" : "null") | |
- | |
- if (isNewArchitectureEnabled() && registrationCompat) { | |
- def reactAndroidProject = project(':ReactAndroid') | |
- externalNativeBuild { | |
- ndkBuild { | |
- arguments "APP_PLATFORM=android-21", | |
- "APP_STL=c++_shared", | |
- "NDK_TOOLCHAIN_VERSION=clang", | |
- "GENERATED_SRC_DIR=$buildDir/generated/source", // for react_codegen_* in this library's codegen/jni | |
- "PROJECT_BUILD_DIR=${appProject.buildDir}", // for REACT_NDK_EXPORT_DIR in ReactAndroid's Android-prebuilt.mk | |
- "REACT_ANDROID_DIR=${reactAndroidProject.projectDir}", | |
- "REACT_ANDROID_BUILD_DIR=${reactAndroidProject.buildDir}", | |
- "CODEGEN_MODULE_NAME=$codegenViewModuleName" | |
- cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" | |
- cppFlags "-std=c++17" | |
- targets "${codegenViewModuleName}_registration" | |
- } | |
- } | |
- } | |
- } | |
- | |
- if (isNewArchitectureEnabled() && registrationCompat) { | |
- // We configure the NDK build only if you decide to opt-in for the New Architecture. | |
- externalNativeBuild { | |
- ndkBuild { | |
- path "Android.mk" | |
- } | |
- } | |
} | |
buildTypes { | |
diff --git a/android/registration.cpp b/android/registration.cpp | |
deleted file mode 100644 | |
index 0e40e75dc03fbf18d62e999813cf9be2f0433edd..0000000000000000000000000000000000000000 | |
--- a/android/registration.cpp | |
+++ /dev/null | |
@@ -1,18 +0,0 @@ | |
-#include <CoreComponentsRegistry.h> | |
-#include CODEGEN_COMPONENT_DESCRIPTOR_H | |
- | |
-namespace facebook { | |
-namespace react { | |
- | |
-void registerProviders() { | |
- auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); | |
- providerRegistry->add(concreteComponentDescriptorProvider<RNCViewPagerComponentDescriptor>()); | |
-} | |
- | |
-} | |
-} | |
- | |
-JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | |
- facebook::react::registerProviders(); | |
- return JNI_VERSION_1_6; | |
-} | |
\ No newline at end of file | |
diff --git a/android/src/main/jni/CMakeLists.txt b/android/src/main/jni/CMakeLists.txt | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..5579fd8876baaaaec5ea67457709efcbcdb2d297 | |
--- /dev/null | |
+++ b/android/src/main/jni/CMakeLists.txt | |
@@ -0,0 +1,73 @@ | |
+cmake_minimum_required(VERSION 3.13) | |
+set(CMAKE_VERBOSE_MAKEFILE on) | |
+ | |
+set(LIB_LITERAL RNCViewPager) | |
+set(LIB_TARGET_NAME react_codegen_${LIB_LITERAL}) | |
+ | |
+set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) | |
+set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../common/cpp) | |
+set(LIB_ANDROID_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni) | |
+set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/renderer/components/${LIB_LITERAL}) | |
+ | |
+add_compile_options( | |
+ -fexceptions | |
+ -frtti | |
+ -std=c++17 | |
+ -Wall | |
+ -Wpedantic | |
+ -Wno-gnu-zero-variadic-macro-arguments | |
+) | |
+ | |
+file(GLOB LIB_CUSTOM_SRCS CONFIGURE_DEPENDS *.cpp ${LIB_COMMON_DIR}/react/renderer/components/${LIB_LITERAL}/*.cpp) | |
+file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_JNI_DIR}/*.cpp ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp) | |
+ | |
+add_library( | |
+ ${LIB_TARGET_NAME} | |
+ SHARED | |
+ ${LIB_CUSTOM_SRCS} | |
+ ${LIB_CODEGEN_SRCS} | |
+) | |
+ | |
+target_include_directories( | |
+ ${LIB_TARGET_NAME} | |
+ PUBLIC | |
+ . | |
+ ${LIB_COMMON_DIR} | |
+ ${LIB_ANDROID_GENERATED_JNI_DIR} | |
+ ${LIB_ANDROID_GENERATED_COMPONENTS_DIR} | |
+) | |
+ | |
+target_link_libraries( | |
+ ${LIB_TARGET_NAME} | |
+ fbjni | |
+ folly_runtime | |
+ glog | |
+ jsi | |
+ react_codegen_rncore | |
+ react_debug | |
+ react_nativemodule_core | |
+ react_render_core | |
+ react_render_debug | |
+ react_render_graphics | |
+ react_render_mapbuffer | |
+ rrc_view | |
+ turbomodulejsijni | |
+ yoga | |
+ react_utils | |
+) | |
+ | |
+target_compile_options( | |
+ ${LIB_TARGET_NAME} | |
+ PRIVATE | |
+ -DLOG_TAG=\"ReactNative\" | |
+ -fexceptions | |
+ -frtti | |
+ -std=c++17 | |
+ -Wall | |
+) | |
+ | |
+target_include_directories( | |
+ ${CMAKE_PROJECT_NAME} | |
+ PUBLIC | |
+ ${CMAKE_CURRENT_SOURCE_DIR} | |
+) | |
diff --git a/android/src/main/jni/RNCViewPager.h b/android/src/main/jni/RNCViewPager.h | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..34720fa02ba2fcd1a549739b3d5dfa84923bf875 | |
--- /dev/null | |
+++ b/android/src/main/jni/RNCViewPager.h | |
@@ -0,0 +1,17 @@ | |
+#pragma once | |
+ | |
+#include <ReactCommon/JavaTurboModule.h> | |
+#include <ReactCommon/TurboModule.h> | |
+#include <jsi/jsi.h> | |
+#include <react/renderer/components/RNCViewPager/RNCViewPagerComponentDescriptor.h> | |
+ | |
+namespace facebook { | |
+namespace react { | |
+ | |
+ | |
+ | |
+JSI_EXPORT | |
+std::shared_ptr<TurboModule> RNCViewPager_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms); | |
+ | |
+} // namespace react | |
+} // namespace facebook | |
diff --git a/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerComponentDescriptor.h b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerComponentDescriptor.h | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..9c6a8ec4342678bdb2e898d480ff98fa8be9747c | |
--- /dev/null | |
+++ b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerComponentDescriptor.h | |
@@ -0,0 +1,12 @@ | |
+#pragma once | |
+ | |
+#include "RNCViewPagerShadowNode.h" | |
+#include <react/renderer/core/ConcreteComponentDescriptor.h> | |
+ | |
+namespace facebook { | |
+namespace react { | |
+ | |
+using RNCViewPagerComponentDescriptor = ConcreteComponentDescriptor<RNCViewPagerShadowNode>; | |
+ | |
+} | |
+} | |
\ No newline at end of file | |
diff --git a/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerShadowNode.cpp b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerShadowNode.cpp | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..a0a29e52e4101c41e4a5da114776cf4152d4fe35 | |
--- /dev/null | |
+++ b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerShadowNode.cpp | |
@@ -0,0 +1,35 @@ | |
+#include "RNCViewPagerShadowNode.h" | |
+ | |
+#include <react/debug/react_native_assert.h> | |
+#include <react/renderer/core/LayoutMetrics.h> | |
+ | |
+namespace facebook { | |
+namespace react { | |
+ | |
+extern const char RNCViewPagerComponentName[] = "RNCViewPager"; | |
+ | |
+void RNCViewPagerShadowNode::updateStateIfNeeded() { | |
+ ensureUnsealed(); | |
+ | |
+ auto contentBoundingRect = Rect{}; | |
+ for (const auto &childNode : getLayoutableChildNodes()) { | |
+ contentBoundingRect.unionInPlace(childNode->getLayoutMetrics().frame); | |
+ } | |
+ | |
+ auto state = getStateData(); | |
+ | |
+ if (state.contentBoundingRect != contentBoundingRect) { | |
+ state.contentBoundingRect = contentBoundingRect; | |
+ setStateData(std::move(state)); | |
+ } | |
+} | |
+ | |
+#pragma mark - LayoutableShadowNode | |
+ | |
+void RNCViewPagerShadowNode::layout(LayoutContext layoutContext) { | |
+ ConcreteViewShadowNode::layout(layoutContext); | |
+ updateStateIfNeeded(); | |
+} | |
+ | |
+} | |
+} | |
\ No newline at end of file | |
diff --git a/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerShadowNode.h b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerShadowNode.h | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..939e921256389b689174a621d88c965c721a169e | |
--- /dev/null | |
+++ b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerShadowNode.h | |
@@ -0,0 +1,32 @@ | |
+#pragma once | |
+ | |
+#include <jsi/jsi.h> | |
+#include <react/renderer/components/RNCViewPager/EventEmitters.h> | |
+#include <react/renderer/components/RNCViewPager/Props.h> | |
+#include <react/renderer/components/RNCViewPager/RNCViewPagerState.h> | |
+#include <react/renderer/components/view/ConcreteViewShadowNode.h> | |
+#include <react/renderer/core/LayoutContext.h> | |
+ | |
+namespace facebook { | |
+namespace react { | |
+ | |
+JSI_EXPORT extern const char RNCViewPagerComponentName[]; | |
+ | |
+class JSI_EXPORT RNCViewPagerShadowNode final : public ConcreteViewShadowNode< | |
+ RNCViewPagerComponentName, | |
+ RNCViewPagerProps, | |
+ RNCViewPagerEventEmitter, | |
+ RNCViewPagerState> { | |
+public: | |
+ using ConcreteViewShadowNode::ConcreteViewShadowNode; | |
+ | |
+#pragma mark - LayoutableShadowNode | |
+ | |
+ void layout(LayoutContext layoutContext) override; | |
+ | |
+private: | |
+ void updateStateIfNeeded(); | |
+}; | |
+ | |
+} | |
+} | |
\ No newline at end of file | |
diff --git a/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerState.cpp b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerState.cpp | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..91b258b0431dde4d3f506e040fc30f3407a899f6 | |
--- /dev/null | |
+++ b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerState.cpp | |
@@ -0,0 +1,11 @@ | |
+#include "RNCViewPagerState.h" | |
+ | |
+namespace facebook { | |
+namespace react { | |
+ | |
+Size RNCViewPagerState::getContentSize() const { | |
+ return contentBoundingRect.size; | |
+} | |
+ | |
+} | |
+} | |
\ No newline at end of file | |
diff --git a/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerState.h b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerState.h | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..f0db7061a534e7c422247581b1017b2ef9963184 | |
--- /dev/null | |
+++ b/common/cpp/react/renderer/components/RNCViewPager/RNCViewPagerState.h | |
@@ -0,0 +1,42 @@ | |
+#pragma once | |
+ | |
+#include <jsi/jsi.h> | |
+#include <react/renderer/graphics/Geometry.h> | |
+ | |
+#ifdef ANDROID | |
+#include <folly/dynamic.h> | |
+#include <react/renderer/mapbuffer/MapBuffer.h> | |
+#include <react/renderer/mapbuffer/MapBufferBuilder.h> | |
+#endif | |
+ | |
+namespace facebook { | |
+namespace react { | |
+ | |
+class JSI_EXPORT RNCViewPagerState final { | |
+public: | |
+ using Shared = std::shared_ptr<const RNCViewPagerState>; | |
+ | |
+ RNCViewPagerState(){}; | |
+ | |
+#ifdef ANDROID | |
+ RNCViewPagerState(RNCViewPagerState const &previousState,folly::dynamic data){}; | |
+ /* | |
+ * Empty implementation for Android because it doesn't use this class. | |
+ */ | |
+ folly::dynamic getDynamic() const { | |
+ return {}; | |
+ }; | |
+ | |
+ MapBuffer getMapBuffer() const { | |
+ return MapBufferBuilder::EMPTY(); | |
+ }; | |
+#endif | |
+ | |
+ Point contentOffset; | |
+ Rect contentBoundingRect; | |
+ | |
+ Size getContentSize() const; | |
+}; | |
+ | |
+} | |
+} | |
\ No newline at end of file | |
diff --git a/ios/Fabric/RNCPagerViewComponentView.h b/ios/Fabric/RNCPagerViewComponentView.h | |
index 6e4187fa75a9b2058d3202aac24f8044e708307f..a87b809e51e8a8bec763cb7ad72d8f8daed257bd 100644 | |
--- a/ios/Fabric/RNCPagerViewComponentView.h | |
+++ b/ios/Fabric/RNCPagerViewComponentView.h | |
@@ -9,8 +9,6 @@ NS_ASSUME_NONNULL_BEGIN | |
@interface RNCPagerViewComponentView : RCTViewComponentView <UIScrollViewDelegate> | |
-@property(nonatomic) BOOL overdrag; | |
- | |
- (void)setPage:(NSInteger)number; | |
- (void)setPageWithoutAnimation:(NSInteger)number; | |
diff --git a/ios/Fabric/RNCPagerViewComponentView.mm b/ios/Fabric/RNCPagerViewComponentView.mm | |
index 981d619ea8ff9ced84b7ca9519ecf251303174f6..9bb1a230ad0c7da54657d59eeca6d1e5c91193a8 100644 | |
--- a/ios/Fabric/RNCPagerViewComponentView.mm | |
+++ b/ios/Fabric/RNCPagerViewComponentView.mm | |
@@ -15,17 +15,14 @@ | |
using namespace facebook::react; | |
-@interface RNCPagerViewComponentView () <RCTRNCViewPagerViewProtocol, UIPageViewControllerDataSource, UIPageViewControllerDelegate, UIScrollViewDelegate, UIGestureRecognizerDelegate> | |
- | |
-@property(nonatomic, assign) UIPanGestureRecognizer* panGestureRecognizer; | |
- | |
+@interface RNCPagerViewComponentView () <RCTRNCViewPagerViewProtocol, UIScrollViewDelegate> | |
@end | |
@implementation RNCPagerViewComponentView { | |
RNCViewPagerShadowNode::ConcreteState::Shared _state; | |
UIScrollView *_scrollView; | |
UIView *_containerView; | |
- | |
+ | |
CGSize _contentSize; | |
NSInteger _initialPage; | |
} | |
@@ -35,73 +32,29 @@ using namespace facebook::react; | |
if (self = [super initWithFrame:frame]) { | |
static const auto defaultProps = std::make_shared<const RNCViewPagerProps>(); | |
_props = defaultProps; | |
- _nativeChildrenViewControllers = [[NSMutableArray alloc] init]; | |
- _currentIndex = -1; | |
- _destinationIndex = -1; | |
- _layoutDirection = @"ltr"; | |
- _overdrag = NO; | |
- UIPanGestureRecognizer* panGestureRecognizer = [UIPanGestureRecognizer new]; | |
- self.panGestureRecognizer = panGestureRecognizer; | |
- panGestureRecognizer.delegate = self; | |
- [self addGestureRecognizer: panGestureRecognizer]; | |
- | |
+ _initialPage = -1; | |
+ | |
+ _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds]; | |
+ | |
+ _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
+ _scrollView.delaysContentTouches = NO; | |
+ _scrollView.delegate = self; | |
+ _scrollView.pagingEnabled = YES; | |
+ _scrollView.showsHorizontalScrollIndicator = NO; | |
+ _scrollView.showsVerticalScrollIndicator = NO; | |
+ | |
+ [self addSubview:_scrollView]; | |
+ | |
+ _containerView = [[UIView alloc] initWithFrame:CGRectZero]; | |
+ | |
+ [_scrollView addSubview:_containerView]; | |
} | |
return self; | |
} | |
-#pragma mark - React API | |
- | |
-- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index { | |
- UIViewController *wrapper = [[UIViewController alloc] initWithView:childComponentView]; | |
- [_nativeChildrenViewControllers insertObject:wrapper atIndex:index]; | |
-} | |
- | |
-- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index { | |
- [[_nativeChildrenViewControllers objectAtIndex:index].view removeFromSuperview]; | |
- [_nativeChildrenViewControllers objectAtIndex:index].view = nil; | |
- [_nativeChildrenViewControllers removeObjectAtIndex:index]; | |
- | |
- NSInteger maxPage = _nativeChildrenViewControllers.count - 1; | |
- | |
- if (self.currentIndex >= maxPage) { | |
- [self goTo:maxPage animated:NO]; | |
- } | |
-} | |
- | |
- | |
--(void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics { | |
- [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:_layoutMetrics]; | |
- self.contentView.frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame()); | |
- _layoutMetrics = layoutMetrics; | |
-} | |
- | |
- | |
--(void)prepareForRecycle { | |
- [super prepareForRecycle]; | |
- | |
- _nativeChildrenViewControllers = [[NSMutableArray alloc] init]; | |
- [_nativePageViewController.view removeFromSuperview]; | |
- _nativePageViewController = nil; | |
- | |
- _currentIndex = -1; | |
-} | |
- | |
-- (void)shouldDismissKeyboard:(RNCViewPagerKeyboardDismissMode)dismissKeyboard { | |
-#if !TARGET_OS_VISION | |
- UIScrollViewKeyboardDismissMode dismissKeyboardMode = UIScrollViewKeyboardDismissModeNone; | |
- switch (dismissKeyboard) { | |
- case RNCViewPagerKeyboardDismissMode::None: | |
- dismissKeyboardMode = UIScrollViewKeyboardDismissModeNone; | |
- break; | |
- case RNCViewPagerKeyboardDismissMode::OnDrag: | |
- dismissKeyboardMode = UIScrollViewKeyboardDismissModeOnDrag; | |
- break; | |
- } | |
- scrollView.keyboardDismissMode = dismissKeyboardMode; | |
-#endif | |
-} | |
+#pragma mark - React API | |
- (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps{ | |
const auto &oldScreenProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props); | |
@@ -206,23 +159,6 @@ using namespace facebook::react; | |
const auto strongEventEmitter = *std::dynamic_pointer_cast<const RNCViewPagerEventEmitter>(_eventEmitter); | |
strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Settling }); | |
- | |
- if (!_overdrag) { | |
- NSInteger maxIndex = _nativeChildrenViewControllers.count - 1; | |
- BOOL isFirstPage = [self isLtrLayout] ? _currentIndex == 0 : _currentIndex == maxIndex; | |
- BOOL isLastPage = [self isLtrLayout] ? _currentIndex == maxIndex : _currentIndex == 0; | |
- CGFloat contentOffset = [self isHorizontal] ? scrollView.contentOffset.x : scrollView.contentOffset.y; | |
- CGFloat topBound = [self isHorizontal] ? scrollView.bounds.size.width : scrollView.bounds.size.height; | |
- | |
- if ((isFirstPage && contentOffset <= topBound) || (isLastPage && contentOffset >= topBound)) { | |
- CGPoint croppedOffset = [self isHorizontal] ? CGPointMake(topBound, 0) : CGPointMake(0, topBound); | |
- *targetContentOffset = croppedOffset; | |
- | |
- strongEventEmitter.onPageScrollStateChanged(RNCViewPagerEventEmitter::OnPageScrollStateChanged{.pageScrollState = RNCViewPagerEventEmitter::OnPageScrollStateChangedPageScrollState::Idle }); | |
- } | |
- } | |
- | |
- | |
} | |
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { | |
@@ -300,29 +236,6 @@ using namespace facebook::react; | |
} | |
-- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { | |
- | |
- // Recognize simultaneously only if the other gesture is RN Screen's pan gesture (one that is used to perform fullScreenGestureEnabled) | |
- if (gestureRecognizer == self.panGestureRecognizer && [NSStringFromClass([otherGestureRecognizer class]) isEqual: @"RNSPanGestureRecognizer"]) { | |
- UIPanGestureRecognizer* panGestureRecognizer = (UIPanGestureRecognizer*) gestureRecognizer; | |
- CGPoint velocity = [panGestureRecognizer velocityInView:self]; | |
- BOOL isLTR = [self isLtrLayout]; | |
- BOOL isBackGesture = (isLTR && velocity.x > 0) || (!isLTR && velocity.x < 0); | |
- | |
- if (self.currentIndex == 0 && isBackGesture) { | |
- scrollView.panGestureRecognizer.enabled = false; | |
- } else { | |
- const auto &viewProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props); | |
- scrollView.panGestureRecognizer.enabled = viewProps.scrollEnabled; | |
- } | |
- | |
- return YES; | |
- } | |
- const auto &viewProps = *std::static_pointer_cast<const RNCViewPagerProps>(_props); | |
- scrollView.panGestureRecognizer.enabled = viewProps.scrollEnabled; | |
- return NO; | |
-} | |
- | |
@end | |
Class<RCTComponentViewProtocol> RNCViewPagerCls(void) | |
diff --git a/package.json b/package.json | |
index e888b9f81a15bcf1dec56710d62488ece2bae538..f1cbba6ae103afceb7b7edcae080a5388d615912 100644 | |
--- a/package.json | |
+++ b/package.json | |
@@ -13,6 +13,7 @@ | |
"android", | |
"ios", | |
"cpp", | |
+ "react-native.config.js", | |
"react-native-pager-view.podspec", | |
"!lib/typescript/example", | |
"!android/build", | |
diff --git a/react-native-pager-view.podspec b/react-native-pager-view.podspec | |
index 879a39fc9cfc1f3afcc762dbdb9ea460b1522a0e..d28edada0d68c1df8d932763f6e65417a60f912f 100644 | |
--- a/react-native-pager-view.podspec | |
+++ b/react-native-pager-view.podspec | |
@@ -2,6 +2,7 @@ require "json" | |
package = JSON.parse(File.read(File.join(__dir__, "package.json"))) | |
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32' | |
+new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1' | |
Pod::Spec.new do |s| | |
s.name = "react-native-pager-view" | |
@@ -16,6 +17,14 @@ Pod::Spec.new do |s| | |
s.source_files = "ios/**/*.{h,m,mm}" | |
+ if new_arch_enabled | |
+ s.subspec "common" do |ss| | |
+ ss.source_files = "common/cpp/**/*.{cpp,h}" | |
+ ss.header_dir = "RNCViewPager" | |
+ ss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/common/cpp\"" } | |
+ end | |
+ end | |
+ | |
# install_modules_dependencies has been defined in RN 0.70 | |
# This check ensure that the library can work on older versions of RN | |
if defined?(install_modules_dependencies) | |
@@ -24,7 +33,7 @@ Pod::Spec.new do |s| | |
s.dependency "React-Core" | |
# Don't install the dependencies when we run `pod install` in the old architecture. | |
- if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then | |
+ if new_arch_enabled then | |
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1" | |
s.pod_target_xcconfig = { | |
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", | |
diff --git a/react-native.config.js b/react-native.config.js | |
new file mode 100644 | |
index 0000000000000000000000000000000000000000..209a3b8ea56b184c42a9911f313f6bea5585a678 | |
--- /dev/null | |
+++ b/react-native.config.js | |
@@ -0,0 +1,29 @@ | |
+let supportsCodegenConfig = false; | |
+try { | |
+ const rnCliAndroidVersion = require.main.require( | |
+ '@react-native-community/cli-platform-android/package.json', | |
+ ).version; | |
+ const [major] = rnCliAndroidVersion.split('.'); | |
+ supportsCodegenConfig = major >= 9; | |
+} catch (e) { | |
+ // ignorea | |
+} | |
+ | |
+module.exports = { | |
+ dependency: { | |
+ platforms: { | |
+ android: supportsCodegenConfig | |
+ ? { | |
+ libraryName: 'RNCViewPager', | |
+ componentDescriptors: [ | |
+ 'LEGACY_RNCViewPagerComponentDescriptor', | |
+ 'RNCViewPagerComponentDescriptor', | |
+ ], | |
+ cmakeListsPath: 'src/main/jni/CMakeLists.txt', | |
+ } | |
+ : {}, | |
+ macos: null, | |
+ windows: null, | |
+ }, | |
+ }, | |
+}; | |
diff --git a/src/PagerViewNativeComponent/PagerViewNativeComponent.ts b/src/PagerViewNativeComponent/PagerViewNativeComponent.ts | |
index cb322b8cdb989ed978cda8e0d4435efed10eb06e..79e77a281cdb7af48a1a15f529f7574429630c7e 100644 | |
--- a/src/PagerViewNativeComponent/PagerViewNativeComponent.ts | |
+++ b/src/PagerViewNativeComponent/PagerViewNativeComponent.ts | |
@@ -65,5 +65,5 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({ | |
}); | |
export default codegenNativeComponent<NativeProps>( | |
- 'RNCViewPager' | |
+ 'RNCViewPager', { interfaceOnly: true } | |
) as HostComponent<NativeProps>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment