mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 02:04:55 +00:00
Implement 'decelerationRate' prop
Summary: @public The content that renders within the `WKWebView` instance actually renders inside a `UIScrollView`. On that scroll view, we can adjust the `decelerationRate`, which controls how fast the view stops scrolling after the user lets go while scrolling. In this diff, I implemented the `decelerationRate` prop for `WKWebView`, which gets forwarded to the `UIScrollView` instance underlying the web view. **Note:** Even though we accept a floating point value for the deceleration rate, the native `UIScrollView` component only allows two inputs: 1. `UIScrollViewDecelerationRateNormal`: 0.998 2. `UIScrollViewDecelerationRateFast`: 0.99 As far as I know, it seems to just round up to the nearest valid `CGFloat` (or down if number > 0.998), for any invalid numbers. Reviewed By: mmmulani Differential Revision: D6307262 fbshipit-source-id: 98c4395702415aa36519f9e9bd84f043be3a5881
This commit is contained in:
parent
1741fe9571
commit
90e85a4adc
@ -21,6 +21,7 @@
|
|||||||
@property (nonatomic, assign) BOOL messagingEnabled;
|
@property (nonatomic, assign) BOOL messagingEnabled;
|
||||||
@property (nonatomic, copy) NSString *injectedJavaScript;
|
@property (nonatomic, copy) NSString *injectedJavaScript;
|
||||||
@property (nonatomic, assign) BOOL scrollEnabled;
|
@property (nonatomic, assign) BOOL scrollEnabled;
|
||||||
|
@property (nonatomic, assign) CGFloat decelerationRate;
|
||||||
|
|
||||||
- (void)postMessage:(NSString *)message;
|
- (void)postMessage:(NSString *)message;
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
static NSString *const MessageHanderName = @"ReactNative";
|
static NSString *const MessageHanderName = @"ReactNative";
|
||||||
|
|
||||||
@interface RCTWKWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler>
|
@interface RCTWKWebView () <WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate>
|
||||||
@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
|
@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
|
||||||
@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
|
@property (nonatomic, copy) RCTDirectEventBlock onLoadingFinish;
|
||||||
@property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
|
@property (nonatomic, copy) RCTDirectEventBlock onLoadingError;
|
||||||
@ -31,6 +31,7 @@ static NSString *const MessageHanderName = @"ReactNative";
|
|||||||
[wkWebViewConfig.userContentController addScriptMessageHandler: self name: MessageHanderName];
|
[wkWebViewConfig.userContentController addScriptMessageHandler: self name: MessageHanderName];
|
||||||
|
|
||||||
_webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
|
_webView = [[WKWebView alloc] initWithFrame:self.bounds configuration: wkWebViewConfig];
|
||||||
|
_webView.scrollView.delegate = self;
|
||||||
_webView.UIDelegate = self;
|
_webView.UIDelegate = self;
|
||||||
_webView.navigationDelegate = self;
|
_webView.navigationDelegate = self;
|
||||||
[self addSubview:_webView];
|
[self addSubview:_webView];
|
||||||
@ -85,6 +86,12 @@ static NSString *const MessageHanderName = @"ReactNative";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
|
||||||
|
{
|
||||||
|
scrollView.decelerationRate = _decelerationRate;
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setScrollEnabled:(BOOL)scrollEnabled
|
- (void)setScrollEnabled:(BOOL)scrollEnabled
|
||||||
{
|
{
|
||||||
_webView.scrollView.scrollEnabled = scrollEnabled;
|
_webView.scrollView.scrollEnabled = scrollEnabled;
|
||||||
|
@ -41,4 +41,8 @@ RCT_CUSTOM_VIEW_PROPERTY(scrollEnabled, BOOL, RCTWKWebView) {
|
|||||||
view.scrollEnabled = json == nil ? true : [RCTConvert BOOL: json];
|
view.scrollEnabled = json == nil ? true : [RCTConvert BOOL: json];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RCTWKWebView) {
|
||||||
|
view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user