blob: e74fed8d8ce20d00e286491793eee5d6b34a6b8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
using System;
using System.Collections.Generic;
#if __UNIFIED__
using UIKit;
#else
using MonoTouch.UIKit;
#endif
namespace Xamarin.Forms.Platform.iOS
{
public static class Extensions
{
public static void ApplyKeyboard(this IUITextInput textInput, Keyboard keyboard)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.None;
textInput.AutocorrectionType = UITextAutocorrectionType.No;
textInput.SpellCheckingType = UITextSpellCheckingType.No;
if (keyboard == Keyboard.Default)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
textInput.AutocorrectionType = UITextAutocorrectionType.Default;
textInput.SpellCheckingType = UITextSpellCheckingType.Default;
textInput.KeyboardType = UIKeyboardType.Default;
}
else if (keyboard == Keyboard.Chat)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
textInput.AutocorrectionType = UITextAutocorrectionType.Yes;
}
else if (keyboard == Keyboard.Email)
textInput.KeyboardType = UIKeyboardType.EmailAddress;
else if (keyboard == Keyboard.Numeric)
textInput.KeyboardType = UIKeyboardType.DecimalPad;
else if (keyboard == Keyboard.Telephone)
textInput.KeyboardType = UIKeyboardType.PhonePad;
else if (keyboard == Keyboard.Text)
{
textInput.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
textInput.AutocorrectionType = UITextAutocorrectionType.Yes;
textInput.SpellCheckingType = UITextSpellCheckingType.Yes;
}
else if (keyboard == Keyboard.Url)
textInput.KeyboardType = UIKeyboardType.Url;
else if (keyboard is CustomKeyboard)
{
var custom = (CustomKeyboard)keyboard;
var capitalizedSentenceEnabled = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence;
var spellcheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) == KeyboardFlags.Spellcheck;
var suggestionsEnabled = (custom.Flags & KeyboardFlags.Suggestions) == KeyboardFlags.Suggestions;
textInput.AutocapitalizationType = capitalizedSentenceEnabled ? UITextAutocapitalizationType.Sentences : UITextAutocapitalizationType.None;
textInput.AutocorrectionType = suggestionsEnabled ? UITextAutocorrectionType.Yes : UITextAutocorrectionType.No;
textInput.SpellCheckingType = spellcheckEnabled ? UITextSpellCheckingType.Yes : UITextSpellCheckingType.No;
}
}
internal static DeviceOrientation ToDeviceOrientation(this UIDeviceOrientation orientation)
{
switch (orientation)
{
case UIDeviceOrientation.Portrait:
return DeviceOrientation.Portrait;
case UIDeviceOrientation.PortraitUpsideDown:
return DeviceOrientation.PortraitDown;
case UIDeviceOrientation.LandscapeLeft:
return DeviceOrientation.LandscapeLeft;
case UIDeviceOrientation.LandscapeRight:
return DeviceOrientation.LandscapeRight;
default:
return DeviceOrientation.Other;
}
}
}
}
|