1 2#import "ReactViewPagerManager.h" 3 4@implementation ReactViewPagerManager 5 6#pragma mark - RTC 7 8RCT_EXPORT_MODULE(RNCViewPager) 9 10RCT_EXPORT_VIEW_PROPERTY(initialPage, NSInteger) 11RCT_EXPORT_VIEW_PROPERTY(pageMargin, NSInteger) 12 13RCT_EXPORT_VIEW_PROPERTY(orientation, UIPageViewControllerNavigationOrientation) 14RCT_EXPORT_VIEW_PROPERTY(onPageSelected, RCTDirectEventBlock) 15RCT_EXPORT_VIEW_PROPERTY(onPageScroll, RCTDirectEventBlock) 16RCT_EXPORT_VIEW_PROPERTY(onPageScrollStateChanged, RCTDirectEventBlock) 17RCT_EXPORT_VIEW_PROPERTY(overdrag, BOOL) 18RCT_EXPORT_VIEW_PROPERTY(layoutDirection, NSString) 19 20 21- (void) goToPage 22 : (nonnull NSNumber *)reactTag index 23 : (nonnull NSNumber *)index animated 24 : (BOOL)animated { 25 [self.bridge.uiManager addUIBlock:^( 26 RCTUIManager *uiManager, 27 NSDictionary<NSNumber *, UIView *> *viewRegistry) { 28 ReactNativePageView *view = (ReactNativePageView *)viewRegistry[reactTag]; 29 if (!view || ![view isKindOfClass:[ReactNativePageView class]]) { 30 RCTLogError(@"Cannot find ReactNativePageView with tag #%@", reactTag); 31 return; 32 } 33 if (!animated || !view.animating) { 34 [view goTo:index.integerValue animated:animated]; 35 } 36 }]; 37} 38 39- (void) changeScrollEnabled 40: (nonnull NSNumber *)reactTag enabled 41: (BOOL)enabled { 42 [self.bridge.uiManager addUIBlock:^( 43 RCTUIManager *uiManager, 44 NSDictionary<NSNumber *, UIView *> *viewRegistry) { 45 ReactNativePageView *view = (ReactNativePageView *)viewRegistry[reactTag]; 46 if (!view || ![view isKindOfClass:[ReactNativePageView class]]) { 47 RCTLogError(@"Cannot find ReactNativePageView with tag #%@", reactTag); 48 return; 49 } 50 [view shouldScroll:enabled]; 51 }]; 52} 53 54RCT_EXPORT_METHOD(setPage 55 : (nonnull NSNumber *)reactTag index 56 : (nonnull NSNumber *)index) { 57 [self goToPage:reactTag index:index animated:true]; 58} 59 60RCT_EXPORT_METHOD(setPageWithoutAnimation 61 : (nonnull NSNumber *)reactTag index 62 : (nonnull NSNumber *)index) { 63 [self goToPage:reactTag index:index animated:false]; 64} 65 66RCT_EXPORT_METHOD(setScrollEnabled 67 : (nonnull NSNumber *)reactTag enabled 68 : (nonnull NSNumber *)enabled) { 69 BOOL isEnabled = [enabled boolValue]; 70 [self changeScrollEnabled:reactTag enabled:isEnabled]; 71} 72 73RCT_CUSTOM_VIEW_PROPERTY(scrollEnabled, BOOL, ReactNativePageView) { 74 [view shouldScroll:[RCTConvert BOOL:json]]; 75} 76 77RCT_CUSTOM_VIEW_PROPERTY(keyboardDismissMode, NSString, ReactNativePageView) { 78 [view shouldDismissKeyboard:[RCTConvert NSString:json]]; 79} 80 81 82- (UIView *)view { 83 return [[ReactNativePageView alloc] initWithEventDispatcher:self.bridge.eventDispatcher]; 84} 85 86@end 87