From 04917afcf5afffad49e50d2a7821c659d04c27f1 Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Tue, 6 Oct 2020 20:04:55 +0200 Subject: [PATCH] chore: Remove Keyboard plugin (#3636) --- .../main/java/com/getcapacitor/Bridge.java | 2 - .../com/getcapacitor/plugin/Keyboard.java | 155 -------- core/src/core-plugin-definitions.ts | 77 ---- .../Capacitor/CAPBridgeViewController.swift | 4 + .../Capacitor/Plugins/DefaultPlugins.m | 10 - ios/Capacitor/Capacitor/Plugins/Keyboard.h | 11 - ios/Capacitor/Capacitor/Plugins/Keyboard.m | 362 ------------------ 7 files changed, 4 insertions(+), 617 deletions(-) delete mode 100644 android/capacitor/src/main/java/com/getcapacitor/plugin/Keyboard.java delete mode 100644 ios/Capacitor/Capacitor/Plugins/Keyboard.h delete mode 100644 ios/Capacitor/Capacitor/Plugins/Keyboard.m diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index 1bbc824d2..0016f8454 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -17,7 +17,6 @@ import android.webkit.WebView; import com.getcapacitor.plugin.App; import com.getcapacitor.plugin.Geolocation; -import com.getcapacitor.plugin.Keyboard; import com.getcapacitor.plugin.LocalNotifications; import com.getcapacitor.plugin.PushNotifications; import com.getcapacitor.plugin.SplashScreen; @@ -383,7 +382,6 @@ private void registerAllPlugins() { this.registerPlugin(BackgroundTask.class); this.registerPlugin(LocalNotifications.class); this.registerPlugin(Geolocation.class); - this.registerPlugin(Keyboard.class); this.registerPlugin(PushNotifications.class); this.registerPlugin(SplashScreen.class); this.registerPlugin(com.getcapacitor.plugin.WebView.class); diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/Keyboard.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/Keyboard.java deleted file mode 100644 index a01a6c158..000000000 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/Keyboard.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.getcapacitor.plugin; - -import android.content.Context; -import android.graphics.Point; -import android.graphics.Rect; -import android.os.Build; -import android.os.Handler; -import android.util.DisplayMetrics; -import android.view.Display; -import android.view.View; -import android.view.ViewTreeObserver; -import android.view.WindowInsets; -import android.view.inputmethod.InputMethodManager; -import com.getcapacitor.JSObject; -import com.getcapacitor.NativePlugin; -import com.getcapacitor.Plugin; -import com.getcapacitor.PluginCall; -import com.getcapacitor.PluginMethod; - -/** - * Ported from https://github.com/ionic-team/cordova-plugin-ionic-keyboard/blob/HEAD/src/android/IonicKeyboard.java - */ -@NativePlugin -public class Keyboard extends Plugin { - private ViewTreeObserver.OnGlobalLayoutListener list; - private View rootView; - - private static final String EVENT_KB_WILL_SHOW = "keyboardWillShow"; - private static final String EVENT_KB_DID_SHOW = "keyboardDidShow"; - private static final String EVENT_KB_WILL_HIDE = "keyboardWillHide"; - private static final String EVENT_KB_DID_HIDE = "keyboardDidHide"; - - @Override - public void load() { - execute( - () -> { - //calculate density-independent pixels (dp) - //http://developer.android.com/guide/practices/screens_support.html - DisplayMetrics dm = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); - final float density = dm.density; - - //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing - rootView = getActivity().getWindow().getDecorView().findViewById(android.R.id.content).getRootView(); - list = - new ViewTreeObserver.OnGlobalLayoutListener() { - int previousHeightDiff = 0; - - @Override - public void onGlobalLayout() { - Rect r = new Rect(); - //r will be populated with the coordinates of your view that area still visible. - rootView.getWindowVisibleDisplayFrame(r); - - // cache properties for later use - int rootViewHeight = rootView.getRootView().getHeight(); - int resultBottom = r.bottom; - int screenHeight; - - if (Build.VERSION.SDK_INT >= 23) { - WindowInsets windowInsets = rootView.getRootWindowInsets(); - int stableInsetBottom = windowInsets.getStableInsetBottom(); - screenHeight = rootViewHeight; - resultBottom = resultBottom + stableInsetBottom; - } else { - // calculate screen height differently for android versions <23: Lollipop 5.x, Marshmallow 6.x - //http://stackoverflow.com/a/29257533/3642890 beware of nexus 5 - Display display = getActivity().getWindowManager().getDefaultDisplay(); - Point size = new Point(); - display.getSize(size); - screenHeight = size.y; - } - - int heightDiff = screenHeight - resultBottom; - - int pixelHeightDiff = (int) (heightDiff / density); - if (pixelHeightDiff > 100 && pixelHeightDiff != previousHeightDiff) { // if more than 100 pixels, its probably a keyboard... - String data = "{ 'keyboardHeight': " + pixelHeightDiff + " }"; - bridge.triggerWindowJSEvent(EVENT_KB_WILL_SHOW, data); - bridge.triggerWindowJSEvent(EVENT_KB_DID_SHOW, data); - JSObject kbData = new JSObject(); - kbData.put("keyboardHeight", pixelHeightDiff); - notifyListeners(EVENT_KB_WILL_SHOW, kbData); - notifyListeners(EVENT_KB_DID_SHOW, kbData); - } else if (pixelHeightDiff != previousHeightDiff && (previousHeightDiff - pixelHeightDiff) > 100) { - bridge.triggerWindowJSEvent(EVENT_KB_WILL_HIDE); - bridge.triggerWindowJSEvent(EVENT_KB_DID_HIDE); - JSObject kbData = new JSObject(); - notifyListeners(EVENT_KB_WILL_HIDE, kbData); - notifyListeners(EVENT_KB_DID_HIDE, kbData); - } - previousHeightDiff = pixelHeightDiff; - } - }; - rootView.getViewTreeObserver().addOnGlobalLayoutListener(list); - } - ); - } - - @PluginMethod - public void show(final PluginCall call) { - execute( - () -> - new Handler() - .postDelayed( - () -> { - ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput( - 0, - InputMethodManager.HIDE_IMPLICIT_ONLY - ); - call.success(); // Thread-safe. - }, - 350 - ) - ); - } - - @PluginMethod - public void hide(final PluginCall call) { - execute( - () -> { - //http://stackoverflow.com/a/7696791/1091751 - InputMethodManager inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - View v = getActivity().getCurrentFocus(); - - if (v == null) { - call.error("Can't close keyboard, not currently focused"); - } else { - inputManager.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); - call.success(); // Thread-safe. - } - } - ); - } - - @PluginMethod - public void setAccessoryBarVisible(PluginCall call) { - call.unimplemented(); - } - - @PluginMethod - public void setStyle(PluginCall call) { - call.unimplemented(); - } - - @PluginMethod - public void setResizeMode(PluginCall call) { - call.unimplemented(); - } - - @PluginMethod - public void setScroll(PluginCall call) { - call.unimplemented(); - } -} diff --git a/core/src/core-plugin-definitions.ts b/core/src/core-plugin-definitions.ts index eb3624a6a..70e1e4652 100644 --- a/core/src/core-plugin-definitions.ts +++ b/core/src/core-plugin-definitions.ts @@ -5,7 +5,6 @@ export interface PluginRegistry { App: AppPlugin; BackgroundTask: BackgroundTaskPlugin; Geolocation: GeolocationPlugin; - Keyboard: KeyboardPlugin; LocalNotifications: LocalNotificationsPlugin; PushNotifications: PushNotificationsPlugin; SplashScreen: SplashScreenPlugin; @@ -261,82 +260,6 @@ export type GeolocationWatchCallback = ( // -export interface KeyboardPlugin extends Plugin { - /** - * Show the keyboard. This method is alpha and may have issues - */ - show(): Promise; - /** - * Hide the keyboard. - */ - hide(): Promise; - /** - * Set whether the accessory bar should be visible on the keyboard. We recommend disabling - * the accessory bar for short forms (login, signup, etc.) to provide a cleaner UI - */ - setAccessoryBarVisible(options: { isVisible: boolean }): Promise; - /** - * Programmatically enable or disable the WebView scroll - */ - setScroll(options: { isDisabled: boolean }): Promise; - /** - * Programmatically set the keyboard style - */ - setStyle(options: KeyboardStyleOptions): Promise; - /** - * Programmatically set the resize mode - */ - setResizeMode(options: KeyboardResizeOptions): Promise; - - addListener( - eventName: 'keyboardWillShow', - listenerFunc: (info: KeyboardInfo) => void, - ): PluginListenerHandle; - addListener( - eventName: 'keyboardDidShow', - listenerFunc: (info: KeyboardInfo) => void, - ): PluginListenerHandle; - addListener( - eventName: 'keyboardWillHide', - listenerFunc: () => void, - ): PluginListenerHandle; - addListener( - eventName: 'keyboardDidHide', - listenerFunc: () => void, - ): PluginListenerHandle; - - /** - * Remove all native listeners for this plugin - */ - removeAllListeners(): void; -} - -export interface KeyboardInfo { - keyboardHeight: number; -} - -export interface KeyboardStyleOptions { - style: KeyboardStyle; -} - -export enum KeyboardStyle { - Dark = 'DARK', - Light = 'LIGHT', -} - -export interface KeyboardResizeOptions { - mode: KeyboardResize; -} - -export enum KeyboardResize { - Body = 'body', - Ionic = 'ionic', - Native = 'native', - None = 'none', -} - -// - export interface LocalNotificationRequest { id: string; } diff --git a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift index a1ff752bf..6ac4b2052 100644 --- a/ios/Capacitor/Capacitor/CAPBridgeViewController.swift +++ b/ios/Capacitor/Capacitor/CAPBridgeViewController.swift @@ -98,6 +98,10 @@ public class CAPBridgeViewController: UIViewController, CAPBridgeDelegate, WKUID bridge = CAPBridge(self, messageHandler, capConfig, specifiedScheme) + if let scrollEnabled = bridge!.config.getValue("ios.scrollEnabled") as? Bool { + webView?.scrollView.isScrollEnabled = scrollEnabled + } + if let backgroundColor = (bridge!.config.getValue("ios.backgroundColor") as? String) ?? (bridge!.config.getValue("backgroundColor") as? String) { webView?.backgroundColor = UIColor.capacitor.color(fromHex: backgroundColor) webView?.scrollView.backgroundColor = UIColor.capacitor.color(fromHex: backgroundColor) diff --git a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m index af8e8bc87..716f830ae 100644 --- a/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m +++ b/ios/Capacitor/Capacitor/Plugins/DefaultPlugins.m @@ -26,16 +26,6 @@ CAP_PLUGIN_METHOD(clearWatch, CAPPluginReturnPromise); ) -CAP_PLUGIN(CAPKeyboard, "Keyboard", - CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setAccessoryBarVisible, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setStyle, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setResizeMode, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(setScroll, CAPPluginReturnPromise); - CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnNone); -) - CAP_PLUGIN(CAPLocalNotificationsPlugin, "LocalNotifications", CAP_PLUGIN_METHOD(schedule, CAPPluginReturnPromise); CAP_PLUGIN_METHOD(requestPermission, CAPPluginReturnPromise); diff --git a/ios/Capacitor/Capacitor/Plugins/Keyboard.h b/ios/Capacitor/Capacitor/Plugins/Keyboard.h deleted file mode 100644 index 4c186233c..000000000 --- a/ios/Capacitor/Capacitor/Plugins/Keyboard.h +++ /dev/null @@ -1,11 +0,0 @@ -#import -#import "CAPPlugin.h" -#import "CAPBridgedPlugin.h" - - -@class CAPPluginCall; - -@interface CAPKeyboard : CAPPlugin - -@end - diff --git a/ios/Capacitor/Capacitor/Plugins/Keyboard.m b/ios/Capacitor/Capacitor/Plugins/Keyboard.m deleted file mode 100644 index e1cc0e29b..000000000 --- a/ios/Capacitor/Capacitor/Plugins/Keyboard.m +++ /dev/null @@ -1,362 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - -#import "Keyboard.h" -#import "CAPBridgedPlugin.h" -#import -#import -#import - -typedef enum : NSUInteger { - ResizeNone, - ResizeNative, - ResizeBody, - ResizeIonic, -} ResizePolicy; - - -@interface CAPKeyboard () - -@property (readwrite, assign, nonatomic) BOOL disableScroll; -@property (readwrite, assign, nonatomic) BOOL hideFormAccessoryBar; -@property (readwrite, assign, nonatomic) BOOL keyboardIsVisible; -@property (nonatomic, readwrite) ResizePolicy keyboardResizes; -@property (readwrite, assign, nonatomic) NSString* keyboardStyle; -@property (nonatomic, readwrite) int paddingBottom; - -@end - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wprotocol" -// suppressing warnings of the type: "Class 'CAPKeyboard' does not conform to protocol 'CAPBridgedPlugin'" -// protocol conformance for this class is implemented by a macro and clang isn't detecting that -@implementation CAPKeyboard - -NSTimer *hideTimer; -NSString* UIClassString; -NSString* WKClassString; -NSString* UITraitsClassString; - -- (void)load -{ - if ([self.bridge.config getValue:@"ios.scrollEnabled"] != nil) { - self.disableScroll = ![[self.bridge.config getValue:@"ios.scrollEnabled"] boolValue]; - } - UIClassString = [@[@"UI", @"Web", @"Browser", @"View"] componentsJoinedByString:@""]; - WKClassString = [@[@"WK", @"Content", @"View"] componentsJoinedByString:@""]; - UITraitsClassString = [@[@"UI", @"Text", @"Input", @"Traits"] componentsJoinedByString:@""]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(statusBarDidChangeFrame:) name:UIApplicationDidChangeStatusBarFrameNotification object: nil]; - - NSString * style = [self getConfigValue:@"style"]; - if ([style isEqualToString:@"dark"]) { - [self changeKeyboardStyle:style.uppercaseString]; - } - - self.keyboardResizes = ResizeNative; - NSString * resizeMode = [self getConfigValue:@"resize"]; - - if ([resizeMode isEqualToString:@"none"]) { - self.keyboardResizes = ResizeNone; - NSLog(@"CAPKeyboard: no resize"); - } else if ([resizeMode isEqualToString:@"ionic"]) { - self.keyboardResizes = ResizeIonic; - NSLog(@"CAPKeyboard: resize mode - ionic"); - } else if ([resizeMode isEqualToString:@"body"]) { - self.keyboardResizes = ResizeBody; - NSLog(@"CAPKeyboard: resize mode - body"); - } - - if (self.keyboardResizes == ResizeNative) { - NSLog(@"CAPKeyboard: resize mode - native"); - } - - self.hideFormAccessoryBar = YES; - - NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; - - [nc addObserver:self selector:@selector(onKeyboardDidHide:) name:UIKeyboardDidHideNotification object:nil]; - [nc addObserver:self selector:@selector(onKeyboardDidShow:) name:UIKeyboardDidShowNotification object:nil]; - [nc addObserver:self selector:@selector(onKeyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; - [nc addObserver:self selector:@selector(onKeyboardWillShow:) name:UIKeyboardWillShowNotification object:nil]; - - [nc removeObserver:self.webView name:UIKeyboardWillHideNotification object:nil]; - [nc removeObserver:self.webView name:UIKeyboardWillShowNotification object:nil]; - [nc removeObserver:self.webView name:UIKeyboardWillChangeFrameNotification object:nil]; - [nc removeObserver:self.webView name:UIKeyboardDidChangeFrameNotification object:nil]; -} - - -#pragma mark Keyboard events - --(void)statusBarDidChangeFrame:(NSNotification *)notification { - [self _updateFrame]; -} - -- (void)resetScrollView -{ - UIScrollView *scrollView = [self.webView scrollView]; - [scrollView setContentInset:UIEdgeInsetsZero]; -} - -- (void)onKeyboardWillHide:(NSNotification *)notification -{ - [self setKeyboardHeight:0 delay:0.01]; - [self resetScrollView]; - hideTimer = [NSTimer scheduledTimerWithTimeInterval:0 repeats:NO block:^(NSTimer * _Nonnull timer) { - [self.bridge triggerWindowJSEventWithEventName:@"keyboardWillHide"]; - [self notifyListeners:@"keyboardWillHide" data:nil]; - }]; - [[NSRunLoop currentRunLoop] addTimer:hideTimer forMode:NSRunLoopCommonModes]; -} - -- (void)onKeyboardWillShow:(NSNotification *)notification -{ - [self changeKeyboardStyle:self.keyboardStyle]; - if (hideTimer != nil) { - [hideTimer invalidate]; - } - CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; - double height = rect.size.height; - - double duration = [[notification.userInfo valueForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]+0.2; - [self setKeyboardHeight:height delay:duration]; - [self resetScrollView]; - - NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height]; - [self.bridge triggerWindowJSEventWithEventName:@"keyboardWillShow" data:data]; - NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]}; - [self notifyListeners:@"keyboardWillShow" data:kbData]; -} - -- (void)onKeyboardDidShow:(NSNotification *)notification -{ - CGRect rect = [[notification.userInfo valueForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; - double height = rect.size.height; - - [self resetScrollView]; - - NSString * data = [NSString stringWithFormat:@"{ 'keyboardHeight': %d }", (int)height]; - [self.bridge triggerWindowJSEventWithEventName:@"keyboardDidShow" data:data]; - NSDictionary * kbData = @{@"keyboardHeight": [NSNumber numberWithDouble:height]}; - [self notifyListeners:@"keyboardDidShow" data:kbData]; -} - -- (void)onKeyboardDidHide:(NSNotification *)notification -{ - [self.bridge triggerWindowJSEventWithEventName:@"keyboardDidHide"]; - [self notifyListeners:@"keyboardDidHide" data:nil]; - [self resetScrollView]; -} - -- (void)setKeyboardHeight:(int)height delay:(NSTimeInterval)delay -{ - if (self.paddingBottom == height) { - return; - } - - self.paddingBottom = height; - - __weak CAPKeyboard* weakSelf = self; - SEL action = @selector(_updateFrame); - [NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:action object:nil]; - if (delay == 0) { - [self _updateFrame]; - } else { - [weakSelf performSelector:action withObject:nil afterDelay:delay inModes:@[NSRunLoopCommonModes]]; - } -} - -- (void)resizeElement:(NSString *)element withPaddingBottom:(int)paddingBottom withScreenHeight:(int)screenHeight -{ - int height = -1; - if (paddingBottom > 0) { - height = screenHeight - paddingBottom; - } - - [self.bridge evalWithJs: [NSString stringWithFormat:@"(function() { var el = %@; var height = %d; if (el) { el.style.height = height > -1 ? height + 'px' : null; } })()", element, height]]; -} - -- (void)_updateFrame -{ - CGSize statusBarSize = [[UIApplication sharedApplication] statusBarFrame].size; - int statusBarHeight = MIN(statusBarSize.width, statusBarSize.height); - - int _paddingBottom = (int)self.paddingBottom; - - if (statusBarHeight == 40) { - _paddingBottom = _paddingBottom + 20; - } - CGRect f, wf = CGRectZero; - id delegate = [[UIApplication sharedApplication] delegate]; - if (delegate != nil && [delegate respondsToSelector:@selector(window)]) { - f = [[delegate window] bounds]; - } - if (self.webView != nil) { - wf = self.webView.frame; - } - switch (self.keyboardResizes) { - case ResizeBody: - { - [self resizeElement:@"document.body" withPaddingBottom:_paddingBottom withScreenHeight:(int)f.size.height]; - break; - } - case ResizeIonic: - { - [self resizeElement:@"document.querySelector('ion-app')" withPaddingBottom:_paddingBottom withScreenHeight:(int)f.size.height]; - break; - } - case ResizeNative: - { - [self.webView setFrame:CGRectMake(wf.origin.x, wf.origin.y, f.size.width - wf.origin.x, f.size.height - wf.origin.y - self.paddingBottom)]; - break; - } - default: - break; - } - [self resetScrollView]; -} - - -#pragma mark HideFormAccessoryBar - -static IMP UIOriginalImp; -static IMP WKOriginalImp; - -- (void)setHideFormAccessoryBar:(BOOL)hideFormAccessoryBar -{ - if (hideFormAccessoryBar == _hideFormAccessoryBar) { - return; - } - Method UIMethod = class_getInstanceMethod(NSClassFromString(UIClassString), @selector(inputAccessoryView)); - Method WKMethod = class_getInstanceMethod(NSClassFromString(WKClassString), @selector(inputAccessoryView)); - if (hideFormAccessoryBar) { - UIOriginalImp = method_getImplementation(UIMethod); - WKOriginalImp = method_getImplementation(WKMethod); - IMP newImp = imp_implementationWithBlock(^(id _s) { - return nil; - }); - method_setImplementation(UIMethod, newImp); - method_setImplementation(WKMethod, newImp); - } else { - method_setImplementation(UIMethod, UIOriginalImp); - method_setImplementation(WKMethod, WKOriginalImp); - } - _hideFormAccessoryBar = hideFormAccessoryBar; -} - -#pragma mark scroll - -- (void)setDisableScroll:(BOOL)disableScroll { - if (disableScroll == _disableScroll) { - return; - } - dispatch_async(dispatch_get_main_queue(), ^{ - if (disableScroll) { - self.webView.scrollView.scrollEnabled = NO; - self.webView.scrollView.delegate = self; - } - else { - self.webView.scrollView.scrollEnabled = YES; - self.webView.scrollView.delegate = nil; - } - }); - _disableScroll = disableScroll; -} - -- (void)scrollViewDidScroll:(UIScrollView *)scrollView { - [scrollView setContentOffset: CGPointZero]; -} - -#pragma mark Plugin interface - -- (void)setAccessoryBarVisible:(CAPPluginCall *)call -{ - BOOL value = [self getBool:call field:@"isVisible" defaultValue:FALSE]; - - NSLog(@"Accessory bar visible change %d", value); - self.hideFormAccessoryBar = !value; - [call success]; -} - -- (void)hide:(CAPPluginCall *)call -{ - dispatch_async(dispatch_get_main_queue(), ^{ - [self.webView endEditing:YES]; - }); - [call success]; -} - -- (void)show:(CAPPluginCall *)call -{ - [call unimplemented]; -} - -- (void)setStyle:(CAPPluginCall *)call -{ - self.keyboardStyle = [self getString:call field:@"style" defaultValue:@"LIGHT"]; - [call success]; -} - -- (void)setResizeMode:(CAPPluginCall *)call -{ - NSString * mode = [self getString:call field:@"mode" defaultValue:@"none"]; - if ([mode isEqualToString:@"ionic"]) { - self.keyboardResizes = ResizeIonic; - } else if ([mode isEqualToString:@"body"]) { - self.keyboardResizes = ResizeBody; - } else if ([mode isEqualToString:@"native"]) { - self.keyboardResizes = ResizeNative; - } else { - self.keyboardResizes = ResizeNone; - } - [call success]; -} - -- (void)setScroll:(CAPPluginCall *)call { - self.disableScroll = [self getBool:call field:@"isDisabled" defaultValue:FALSE]; - [call success]; -} - -- (void)changeKeyboardStyle:(NSString*)style -{ - IMP newImp = [style isEqualToString:@"DARK"] ? imp_implementationWithBlock(^(id _s) { - return UIKeyboardAppearanceDark; - }) : imp_implementationWithBlock(^(id _s) { - return UIKeyboardAppearanceLight; - }); - for (NSString* classString in @[WKClassString, UITraitsClassString]) { - Class c = NSClassFromString(classString); - Method m = class_getInstanceMethod(c, @selector(keyboardAppearance)); - if (m != NULL) { - method_setImplementation(m, newImp); - } else { - class_addMethod(c, @selector(keyboardAppearance), newImp, "l@:"); - } - } - _keyboardStyle = style; -} - -#pragma mark dealloc - -- (void)dealloc -{ - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} - -@end -#pragma clang diagnostic pop -