Skip to content

Commit 1ff88ff

Browse files
committed
Merge branch 'kemcake-master'
2 parents 90724de + 50482a9 commit 1ff88ff

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

ios/RCTWebViewBridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ shouldStartLoadForRequest:(NSMutableDictionary<NSString *, id> *)request
3737
@property (nonatomic, strong) NSURL *URL;
3838
@property (nonatomic, assign) UIEdgeInsets contentInset;
3939
@property (nonatomic, assign) BOOL automaticallyAdjustContentInsets;
40+
@property (nonatomic, assign) BOOL hideKeyboardAccessoryView;
4041
@property (nonatomic, copy) NSString *injectedJavaScript;
4142

4243
- (void)goForward;

ios/RCTWebViewBridge.m

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,20 @@
2525
//source: http://stackoverflow.com/a/23387659/828487
2626
#define NSStringMultiline(...) [[NSString alloc] initWithCString:#__VA_ARGS__ encoding:NSUTF8StringEncoding]
2727

28-
2928
//we don'e need this one since it has been defined in RCTWebView.m
3029
//NSString *const RCTJSNavigationScheme = @"react-js-navigation";
3130
NSString *const RCTWebViewBridgeSchema = @"wvb";
3231

32+
// runtime trick to remove UIWebview keyboard default toolbar
33+
// see: http://stackoverflow.com/questions/19033292/ios-7-uiwebview-keyboard-issue/19042279#19042279
34+
@interface _SwizzleHelper : NSObject @end
35+
@implementation _SwizzleHelper
36+
-(id)inputAccessoryView
37+
{
38+
return nil;
39+
}
40+
@end
41+
3342
@interface RCTWebViewBridge () <UIWebViewDelegate, RCTAutoInsetsProtocol>
3443

3544
@property (nonatomic, copy) RCTDirectEventBlock onLoadingStart;
@@ -165,6 +174,37 @@ - (void)refreshContentInset
165174
updateOffset:YES];
166175
}
167176

177+
-(void)setHideKeyboardAccessoryView:(BOOL)hideKeyboardAccessoryView
178+
{
179+
if (!hideKeyboardAccessoryView) {
180+
return;
181+
}
182+
183+
UIView* subview;
184+
for (UIView* view in _webView.scrollView.subviews) {
185+
if([[view.class description] hasPrefix:@"UIWeb"])
186+
subview = view;
187+
}
188+
189+
if(subview == nil) return;
190+
191+
NSString* name = [NSString stringWithFormat:@"%@_SwizzleHelper", subview.class.superclass];
192+
Class newClass = NSClassFromString(name);
193+
194+
if(newClass == nil)
195+
{
196+
newClass = objc_allocateClassPair(subview.class, [name cStringUsingEncoding:NSASCIIStringEncoding], 0);
197+
if(!newClass) return;
198+
199+
Method method = class_getInstanceMethod([_SwizzleHelper class], @selector(inputAccessoryView));
200+
class_addMethod(newClass, @selector(inputAccessoryView), method_getImplementation(method), method_getTypeEncoding(method));
201+
202+
objc_registerClassPair(newClass);
203+
}
204+
205+
object_setClass(subview, newClass);
206+
}
207+
168208
#pragma mark - UIWebViewDelegate methods
169209

170210
- (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request

ios/RCTWebViewBridgeManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ - (UIView *)view
4444
RCT_EXPORT_VIEW_PROPERTY(injectedJavaScript, NSString)
4545
RCT_EXPORT_VIEW_PROPERTY(contentInset, UIEdgeInsets)
4646
RCT_EXPORT_VIEW_PROPERTY(automaticallyAdjustContentInsets, BOOL)
47+
RCT_EXPORT_VIEW_PROPERTY(hideKeyboardAccessoryView, BOOL)
4748
RCT_EXPORT_VIEW_PROPERTY(onLoadingStart, RCTDirectEventBlock)
4849
RCT_EXPORT_VIEW_PROPERTY(onLoadingFinish, RCTDirectEventBlock)
4950
RCT_EXPORT_VIEW_PROPERTY(onLoadingError, RCTDirectEventBlock)

webview-bridge/index.ios.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ var WebViewBridge = React.createClass({
101101
* Will be called once the message is being sent from webview
102102
*/
103103
onBridgeMessage: PropTypes.func,
104+
105+
hideKeyboardAccessoryView: PropTypes.bool,
104106
},
105107

106108
getInitialState: function() {
@@ -171,7 +173,7 @@ var WebViewBridge = React.createClass({
171173
});
172174
}
173175
};
174-
176+
175177
const props = {...this.props};
176178
delete props.onBridgeMessage;
177179
delete props.onShouldStartLoadWithRequest;

0 commit comments

Comments
 (0)