@@ -11,55 +11,50 @@ namespace NativeCode.Mobile.AppCompat.Renderers.Helpers
11
11
12
12
internal static class KeyboardHelper
13
13
{
14
- private const string KeyboardExtensions = "Xamarin.Forms.Platform.Android.KeyboardExtensions, Xamarin.Forms.Platform.Android" ;
14
+ private const string KeyboardExtensionsType = "Xamarin.Forms.Platform.Android.KeyboardExtensions, Xamarin.Forms.Platform.Android" ;
15
15
16
16
private const string KeyboardExtensionsToInputType = "ToInputType" ;
17
17
18
- private const string KeyboardManager = "Xamarin.Forms.Platform.Android.KeyboardManager, Xamarin.Forms.Platform.Android" ;
18
+ private const string KeyboardManagerType = "Xamarin.Forms.Platform.Android.KeyboardManager, Xamarin.Forms.Platform.Android" ;
19
19
20
20
private const string KeyboardManagerHideKeyboard = "HideKeyboard" ;
21
21
22
22
private const string KeyboardManagerShowKeyboard = "ShowKeyboard" ;
23
23
24
- private const BindingFlags StaticMethodBindingFlags = BindingFlags . NonPublic | BindingFlags . Static ;
24
+ private const BindingFlags StaticInternalMethods = BindingFlags . NonPublic | BindingFlags . Static ;
25
25
26
- public static InputTypes GetInputType ( Keyboard keyboard )
26
+ private static readonly MethodInfo MethodToInputType ;
27
+
28
+ private static readonly MethodInfo MethodHideKeyboard ;
29
+
30
+ private static readonly MethodInfo MethodShowKeyboard ;
31
+
32
+ /// <summary>
33
+ /// Initializes static members of the <see cref="KeyboardHelper"/> class.
34
+ /// </summary>
35
+ static KeyboardHelper ( )
27
36
{
28
- var type = Type . GetType ( KeyboardExtensions , true ) ;
29
- var method = type . GetMethod ( KeyboardExtensionsToInputType ) ;
37
+ var keyboardExtensionsType = Type . GetType ( KeyboardExtensionsType , true ) ;
38
+ MethodToInputType = keyboardExtensionsType . GetMethod ( KeyboardExtensionsToInputType ) ;
30
39
31
- if ( method == null )
32
- {
33
- throw new MissingMethodException ( type . Name , KeyboardExtensionsToInputType ) ;
34
- }
40
+ var keyboardManagerType = Type . GetType ( KeyboardManagerType , true ) ;
41
+ MethodHideKeyboard = keyboardManagerType . GetMethod ( KeyboardManagerHideKeyboard , StaticInternalMethods ) ;
42
+ MethodShowKeyboard = keyboardManagerType . GetMethod ( KeyboardManagerShowKeyboard , StaticInternalMethods ) ;
43
+ }
35
44
36
- return ( InputTypes ) method . Invoke ( null , new object [ ] { keyboard } ) ;
45
+ public static InputTypes GetInputType ( Keyboard keyboard )
46
+ {
47
+ return ( InputTypes ) MethodToInputType . Invoke ( null , new object [ ] { keyboard } ) ;
37
48
}
38
49
39
50
public static void HideKeyboard ( View view )
40
51
{
41
- var type = Type . GetType ( KeyboardManager , true ) ;
42
- var method = type . GetMethod ( KeyboardManagerHideKeyboard , StaticMethodBindingFlags ) ;
43
-
44
- if ( method == null )
45
- {
46
- throw new MissingMethodException ( type . Name , KeyboardManagerHideKeyboard ) ;
47
- }
48
-
49
- method . Invoke ( null , new object [ ] { view } ) ;
52
+ MethodHideKeyboard . Invoke ( null , new object [ ] { view } ) ;
50
53
}
51
54
52
55
public static void ShowKeyboard ( View view )
53
56
{
54
- var type = Type . GetType ( KeyboardManager , true ) ;
55
- var method = type . GetMethod ( KeyboardManagerShowKeyboard , StaticMethodBindingFlags ) ;
56
-
57
- if ( method == null )
58
- {
59
- throw new MissingMethodException ( type . Name , KeyboardManagerShowKeyboard ) ;
60
- }
61
-
62
- method . Invoke ( null , new object [ ] { view } ) ;
57
+ MethodShowKeyboard . Invoke ( null , new object [ ] { view } ) ;
63
58
}
64
59
}
65
60
}
0 commit comments