Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apple/RNCWebViewImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
@property (nonatomic, copy) NSString * _Nullable allowingReadAccessToURL;
@property (nonatomic, copy) NSDictionary * _Nullable basicAuthCredential;
@property (nonatomic, assign) BOOL pullToRefreshEnabled;
@property (nonatomic, assign) BOOL dragInteractionEnabled;
@property (nonatomic, assign) BOOL enableApplePay;
@property (nonatomic, copy) NSArray<NSDictionary *> * _Nullable menuItems;
@property (nonatomic, copy) NSArray<NSString *> * _Nullable suppressMenuItems;
Expand Down
35 changes: 35 additions & 0 deletions apple/RNCWebViewImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ - (instancetype)initWithFrame:(CGRect)frame
_showsHorizontalScrollIndicator = YES;
_showsVerticalScrollIndicator = YES;
_forceLightScrollIndicators = NO;
_dragInteractionEnabled = YES;
_scrollsToTop = YES;
_directionalLockEnabled = YES;
_automaticallyAdjustContentInsets = YES;
Expand Down Expand Up @@ -537,6 +538,9 @@ - (void)didMoveToWindow
[self setHideKeyboardAccessoryView: _savedHideKeyboardAccessoryView];
[self setKeyboardDisplayRequiresUserAction: _savedKeyboardDisplayRequiresUserAction];
[self visitSource];
#if !TARGET_OS_OSX
[self updateDragInteractionState];
#endif
}
#if !TARGET_OS_OSX
// Allow this object to recognize gestures
Expand Down Expand Up @@ -1053,6 +1057,37 @@ - (void)setScrollsToTop:(BOOL)scrollsToTop
}
#endif // !TARGET_OS_OSX

#if !TARGET_OS_OSX
- (void)setDragInteractionEnabled:(BOOL)dragInteractionEnabled
{
_dragInteractionEnabled = dragInteractionEnabled;
[self updateDragInteractionState];
}

- (void)updateDragInteractionState
{
if (@available(iOS 11.0, *)) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self disableDragInteractionsRecursively:_webView];
});
}
}

- (void)disableDragInteractionsRecursively:(UIView *)view
{
if (@available(iOS 11.0, *)) {
for (id<UIInteraction> interaction in view.interactions) {
if ([interaction isKindOfClass:[UIDragInteraction class]]) {
((UIDragInteraction *)interaction).enabled = _dragInteractionEnabled;
}
}
for (UIView *subview in view.subviews) {
[self disableDragInteractionsRecursively:subview];
}
}
}
#endif // !TARGET_OS_OSX

- (void)postMessage:(NSString *)message
{
NSDictionary *eventInitDict = @{@"data": message};
Expand Down
4 changes: 4 additions & 0 deletions apple/RNCWebViewManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ - (RNCView *)view
view.pullToRefreshEnabled = json == nil ? false : [RCTConvert BOOL: json];
}

RCT_CUSTOM_VIEW_PROPERTY(dragInteractionEnabled, BOOL, RNCWebViewImpl) {
view.dragInteractionEnabled = json == nil ? true : [RCTConvert BOOL: json];
}

RCT_CUSTOM_VIEW_PROPERTY(bounces, BOOL, RNCWebViewImpl) {
view.bounces = json == nil ? true : [RCTConvert BOOL: json];
}
Expand Down
1 change: 1 addition & 0 deletions lib/RNCWebViewNativeComponent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export interface NativeProps extends ViewProps {
mediaCapturePermissionGrantType?: WithDefault<'prompt' | 'grant' | 'deny' | 'grantIfSameHostElsePrompt' | 'grantIfSameHostElseDeny', 'prompt'>;
pagingEnabled?: boolean;
pullToRefreshEnabled?: boolean;
dragInteractionEnabled?: boolean;
scrollEnabled?: boolean;
sharedCookiesEnabled?: boolean;
textInteractionEnabled?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion lib/RNCWebViewNativeComponent.d.ts.map

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions lib/WebViewTypes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,13 @@ export interface IOSWebViewProps extends WebViewSharedProps {
*
*/
pullToRefreshEnabled?: boolean;
/**
* Controls whether text can be dragged from the webview.
* Set to false to disable iOS drag-and-drop.
* @platform ios
* @default true
*/
dragInteractionEnabled?: boolean;
/**
* Function that is invoked when the client needs to download a file.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/WebViewTypes.d.ts.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/RNCWebViewNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export interface NativeProps extends ViewProps {
mediaCapturePermissionGrantType?: WithDefault<'prompt' | 'grant' | 'deny' | 'grantIfSameHostElsePrompt' | 'grantIfSameHostElseDeny', 'prompt'>;
pagingEnabled?: boolean;
pullToRefreshEnabled?: boolean;
dragInteractionEnabled?: boolean;
scrollEnabled?: boolean;
sharedCookiesEnabled?: boolean;
textInteractionEnabled?: boolean;
Expand Down
8 changes: 8 additions & 0 deletions src/WebViewTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,14 @@ export interface IOSWebViewProps extends WebViewSharedProps {
*/
pullToRefreshEnabled?: boolean;

/**
* Controls whether text can be dragged from the webview.
* Set to false to disable iOS drag-and-drop.
* @platform ios
* @default true
*/
dragInteractionEnabled?: boolean;

/**
* Function that is invoked when the client needs to download a file.
*
Expand Down
Loading