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