react-native-macos/React/Base/RCTRootView.h

188 строки
6.2 KiB
C
Исходник Обычный вид История

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <UIKit/UIKit.h>
#import <React/RCTBridge.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcherProtocol.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.
*/
#if defined(__cplusplus)
extern "C"
#else
extern
#endif
NS_ASSUME_NONNULL_BEGIN
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
2015-04-02 17:33:21 +03:00
/**
* - Designated initializer -
*/
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(nullable NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
/**
* - Convenience initializer -
* The frame will default to CGRectZero.
*/
2015-04-02 17:33:21 +03:00
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(nullable NSDictionary *)initialProperties;
2015-03-26 04:59:42 +03:00
/**
2015-04-02 17:33:21 +03:00
* - 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.
*/
2015-04-02 17:33:21 +03:00
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(nullable NSDictionary *)initialProperties
launchOptions:(nullable NSDictionary *)launchOptions;
/**
* This API allows RCTRootView users to know if the root view is backed by the bridge.
*/
@property (nonatomic, readonly) BOOL hasBridge;
/**
* This API allows users of RCTRootView to access other NativeModules, without
* directly accessing the bridge.
*/
@property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry;
/**
* 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.
*/
2015-03-26 04:59:42 +03:00
@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.
*/
2015-04-02 17:33:21 +03:00
@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, nullable) NSDictionary *appProperties;
/**
* The size flexibility mode of the root view.
*/
@property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility;
/*
* The minimum size of the root view, defaults to CGSizeZero.
*/
@property (nonatomic, assign) CGSize minimumSize;
/**
* The delegate that handles intrinsic size updates.
*/
@property (nonatomic, weak, nullable) id<RCTRootViewDelegate> delegate;
/**
2015-04-12 01:08:00 +03:00
* The backing view controller of the root view.
*/
@property (nonatomic, weak, nullable) UIViewController *reactViewController;
2015-04-02 17:33:21 +03:00
2015-04-12 01:08:00 +03:00
/**
* The React-managed contents view of the root view.
*/
2015-04-02 17:33:21 +03:00
@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, nullable) UIView *loadingView;
/**
* 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` property instead.
*/
@property (readonly, nonatomic, assign) CGSize intrinsicSize __deprecated_msg("Use `intrinsicContentSize` instead.");
Deprecation of `-[RCTRootView cancelTouches]` Summary: The necessity of this feature was removed in 2017. To intercept React Native gesture recognizer, implement UIGestureRecognizer delegate for conflicting gestures. Here is the quote from the internal note: > Previously we had lots of super weird bugs where React Native would inaccurately recognize touch gestures which were meant to be addressed by the native environment. Usually, these bugs occurred as unintentional taps happening right after swipe gestures. In all of these cases, we had to manually call method `cancelTouches` as part of an external gesture recognition process which prevented touch delivery to React Native. Furthermore, we had to delay touch delivery to React Native to wait for these cancellations. That code always looked like a hack (in the bad meaning of this word), like in some random place something dispatch event to another random place where something finally calls `cancelTouches`, yak. It was super annoying because it required adding this hack to all existing apps and screens, and because sometimes it was even too late to cancel touches. > We fixed that. Instead of delaying touch delivery and waiting for calls to `cancelTouches`, we set up the React Native gesture recognizer in such way that it always agrees to fail in favor of any native gestures (from non-RN-based and served views which are placed higher in a hierarchy). React Native will now cancel all active touches itself so that we no longer need to call `cancelTouches` manually. We already removed all these calls and supported code from Facebook and Instagram. See also: https://github.com/facebook/react-native/pull/25193 Reviewed By: PeteTheHeat Differential Revision: D15734129 fbshipit-source-id: 289f77a437cb40199c591153b5801d24d0c10d1e
2019-06-11 17:25:18 +03:00
/**
* This methods is deprecated and will be removed soon.
* To interrupt a React Native gesture recognizer, use the standard
* `UIGestureRecognizer` negotiation process.
* See `UIGestureRecognizerDelegate` for more details.
*/
- (void)cancelTouches;
@end
NS_ASSUME_NONNULL_END