RCTRootView.h
6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
@protocol RCTRootViewDelegate;
/**
* This enum is used to define size flexibility type of the root view.
* If a dimension is flexible, the view will recalculate that dimension
* so the content fits. Recalculations are performed when the root's frame,
* size flexibility mode or content size changes. After a recalculation,
* rootViewDidChangeIntrinsicSize method of the RCTRootViewDelegate will be called.
*/
typedef NS_ENUM(NSInteger, RCTRootViewSizeFlexibility) {
RCTRootViewSizeFlexibilityNone = 0,
RCTRootViewSizeFlexibilityWidth = 1 << 0,
RCTRootViewSizeFlexibilityHeight = 1 << 1,
RCTRootViewSizeFlexibilityWidthAndHeight = RCTRootViewSizeFlexibilityWidth | RCTRootViewSizeFlexibilityHeight,
};
/**
* This notification is sent when the first subviews are added to the root view
* after the application has loaded. This is used to hide the `loadingView`, and
* is a good indicator that the application is ready to use.
*/
extern NSString *const RCTContentDidAppearNotification;
/**
* Native view used to host React-managed views within the app. Can be used just
* like any ordinary UIView. You can have multiple RCTRootViews on screen at
* once, all controlled by the same JavaScript application.
*/
@interface RCTRootView : UIView
/**
* - Designated initializer -
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
/**
* - Convenience initializer -
* A bridge will be created internally.
* This initializer is intended to be used when the app has a single RCTRootView,
* otherwise create an `RCTBridge` and pass it in via `initWithBridge:moduleName:`
* to all the instances.
*/
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
launchOptions:(NSDictionary *)launchOptions;
/**
* The name of the JavaScript module to execute within the
* specified scriptURL (required). Setting this will not have
* any immediate effect, but it must be done prior to loading
* the script.
*/
@property (nonatomic, copy, readonly) NSString *moduleName;
/**
* The bridge used by the root view. Bridges can be shared between multiple
* root views, so you can use this property to initialize another RCTRootView.
*/
@property (nonatomic, strong, readonly) RCTBridge *bridge;
/**
* The properties to apply to the view. Use this property to update
* application properties and rerender the view. Initialized with
* initialProperties argument of the initializer.
*
* Set this property only on the main thread.
*/
@property (nonatomic, copy, readwrite) NSDictionary *appProperties;
/**
* The size flexibility mode of the root view.
*/
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
/**
* The delegate that handles intrinsic size updates.
*/
@property (nonatomic, weak) id<RCTRootViewDelegate> delegate;
/**
* The backing view controller of the root view.
*/
@property (nonatomic, weak) UIViewController *reactViewController;
/**
* The React-managed contents view of the root view.
*/
@property (nonatomic, strong, readonly) UIView *contentView;
/**
* A view to display while the JavaScript is loading, so users aren't presented
* with a blank screen. By default this is nil, but you can override it with
* (for example) a UIActivityIndicatorView or a placeholder image.
*/
@property (nonatomic, strong) UIView *loadingView;
/**
* Calling this will result in emitting a "touches cancelled" event to js,
* which effectively cancels all js "gesture recognizers" such as touchable components
* (unless they explicitely ignore cancellation events, but no one should do that).
*
* This API is exposed for integration purposes where you embed RN rootView
* in a native view with a native gesture recognizer,
* whose activation should prevent any in-flight js "gesture recognizer" from activating.
*
* An example would be RN rootView embedded in an UIScrollView.
* When you touch down on a touchable component and drag your finger up,
* you don't want any touch to be registered as soon as the UIScrollView starts scrolling.
*
* Note that this doesn't help with tapping on a touchable element that is being scrolled,
* unless you can call cancelTouches exactly between "touches began" and "touches ended" events.
* This is a reason why this API may be soon removed in favor of a better solution.
*/
- (void)cancelTouches;
/**
* When set, any touches on the RCTRootView that are not matched up to any of the child
* views will be passed to siblings of the RCTRootView. See -[UIView hitTest:withEvent:]
* for details on iOS hit testing.
*
* Enable this to support a semi-transparent RN view that occupies the whole screen but
* has visible content below it that the user can interact with.
*
* The default value is NO.
*/
@property (nonatomic, assign) BOOL passThroughTouches;
/**
* Timings for hiding the loading view after the content has loaded. Both of
* these values default to 0.25 seconds.
*/
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDelay;
@property (nonatomic, assign) NSTimeInterval loadingViewFadeDuration;
@end
@interface RCTRootView (Deprecated)
/**
* The intrinsic size of the root view's content. This is set right before the
* `rootViewDidChangeIntrinsicSize` method of `RCTRootViewDelegate` is called.
* This property is deprecated and will be removed in next releases.
* Use UIKit `intrinsicContentSize` propery instead.
*/
@property (readonly, nonatomic, assign) CGSize intrinsicSize
__deprecated_msg("Use `intrinsicContentSize` instead.");
@end