react-native-umui 1.3.59 → 1.3.87

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/lib/commonjs/Accordion.js +46 -0
  2. package/lib/commonjs/Accordion.js.map +1 -0
  3. package/lib/commonjs/Badge.js +1 -1
  4. package/lib/commonjs/Badge.js.map +1 -1
  5. package/lib/commonjs/Button.js +10 -7
  6. package/lib/commonjs/Button.js.map +1 -1
  7. package/lib/commonjs/Checkbox.js +0 -1
  8. package/lib/commonjs/Checkbox.js.map +1 -1
  9. package/lib/commonjs/Divider.js +8 -8
  10. package/lib/commonjs/Divider.js.map +1 -1
  11. package/lib/commonjs/EasyIn.js +43 -0
  12. package/lib/commonjs/EasyIn.js.map +1 -1
  13. package/lib/commonjs/FlatList.js +2 -1
  14. package/lib/commonjs/FlatList.js.map +1 -1
  15. package/lib/commonjs/FlatPanel.js.map +1 -1
  16. package/lib/commonjs/Grid.js.map +1 -1
  17. package/lib/commonjs/InputField.js +2 -0
  18. package/lib/commonjs/InputField.js.map +1 -1
  19. package/lib/commonjs/Line.js +0 -1
  20. package/lib/commonjs/Line.js.map +1 -1
  21. package/lib/commonjs/Load.js +1 -2
  22. package/lib/commonjs/Load.js.map +1 -1
  23. package/lib/commonjs/Numeral.js +6 -1
  24. package/lib/commonjs/Numeral.js.map +1 -1
  25. package/lib/commonjs/PanelRK.js +1 -1
  26. package/lib/commonjs/PanelRK.js.map +1 -1
  27. package/lib/commonjs/Phone.js +12 -5
  28. package/lib/commonjs/Phone.js.map +1 -1
  29. package/lib/commonjs/Press.js.map +1 -1
  30. package/lib/commonjs/Radio.js +0 -1
  31. package/lib/commonjs/Radio.js.map +1 -1
  32. package/lib/commonjs/Scroll.js +2 -2
  33. package/lib/commonjs/Scroll.js.map +1 -1
  34. package/lib/commonjs/Tab.js +5 -14
  35. package/lib/commonjs/Tab.js.map +1 -1
  36. package/lib/commonjs/Text.js +22 -2
  37. package/lib/commonjs/Text.js.map +1 -1
  38. package/lib/commonjs/TextInput.js +69 -1
  39. package/lib/commonjs/TextInput.js.map +1 -1
  40. package/lib/commonjs/regions.js +14 -1
  41. package/lib/commonjs/regions.js.map +1 -1
  42. package/lib/commonjs/shadows.js +3 -2
  43. package/lib/commonjs/shadows.js.map +1 -1
  44. package/lib/module/Accordion.js +37 -0
  45. package/lib/module/Accordion.js.map +1 -0
  46. package/lib/module/Badge.js +1 -1
  47. package/lib/module/Badge.js.map +1 -1
  48. package/lib/module/Button.js +10 -7
  49. package/lib/module/Button.js.map +1 -1
  50. package/lib/module/Checkbox.js +0 -1
  51. package/lib/module/Checkbox.js.map +1 -1
  52. package/lib/module/Divider.js +8 -8
  53. package/lib/module/Divider.js.map +1 -1
  54. package/lib/module/EasyIn.js +40 -0
  55. package/lib/module/EasyIn.js.map +1 -1
  56. package/lib/module/FlatList.js +2 -1
  57. package/lib/module/FlatList.js.map +1 -1
  58. package/lib/module/FlatPanel.js.map +1 -1
  59. package/lib/module/Grid.js.map +1 -1
  60. package/lib/module/InputField.js +2 -0
  61. package/lib/module/InputField.js.map +1 -1
  62. package/lib/module/Line.js +0 -1
  63. package/lib/module/Line.js.map +1 -1
  64. package/lib/module/Load.js +1 -2
  65. package/lib/module/Load.js.map +1 -1
  66. package/lib/module/Numeral.js +6 -1
  67. package/lib/module/Numeral.js.map +1 -1
  68. package/lib/module/PanelRK.js +2 -2
  69. package/lib/module/PanelRK.js.map +1 -1
  70. package/lib/module/Phone.js +12 -5
  71. package/lib/module/Phone.js.map +1 -1
  72. package/lib/module/Press.js.map +1 -1
  73. package/lib/module/Radio.js +0 -1
  74. package/lib/module/Radio.js.map +1 -1
  75. package/lib/module/Scroll.js +2 -2
  76. package/lib/module/Scroll.js.map +1 -1
  77. package/lib/module/Tab.js +5 -14
  78. package/lib/module/Tab.js.map +1 -1
  79. package/lib/module/Text.js +21 -2
  80. package/lib/module/Text.js.map +1 -1
  81. package/lib/module/TextInput.js +69 -2
  82. package/lib/module/TextInput.js.map +1 -1
  83. package/lib/module/regions.js +14 -1
  84. package/lib/module/regions.js.map +1 -1
  85. package/lib/module/shadows.js +3 -2
  86. package/lib/module/shadows.js.map +1 -1
  87. package/lib/typescript/src/Accordion.d.ts +12 -0
  88. package/lib/typescript/src/Accordion.d.ts.map +1 -0
  89. package/lib/typescript/src/Badge.d.ts.map +1 -1
  90. package/lib/typescript/src/Button.d.ts +1 -1
  91. package/lib/typescript/src/Button.d.ts.map +1 -1
  92. package/lib/typescript/src/Checkbox.d.ts.map +1 -1
  93. package/lib/typescript/src/Divider.d.ts +3 -0
  94. package/lib/typescript/src/Divider.d.ts.map +1 -1
  95. package/lib/typescript/src/EasyIn.d.ts +3 -0
  96. package/lib/typescript/src/EasyIn.d.ts.map +1 -1
  97. package/lib/typescript/src/FlatList.d.ts.map +1 -1
  98. package/lib/typescript/src/FlatPanel.d.ts.map +1 -1
  99. package/lib/typescript/src/Grid.d.ts.map +1 -1
  100. package/lib/typescript/src/InputField.d.ts +1 -2
  101. package/lib/typescript/src/InputField.d.ts.map +1 -1
  102. package/lib/typescript/src/Line.d.ts.map +1 -1
  103. package/lib/typescript/src/Load.d.ts.map +1 -1
  104. package/lib/typescript/src/Numeral.d.ts.map +1 -1
  105. package/lib/typescript/src/PanelRK.d.ts +2 -2
  106. package/lib/typescript/src/PanelRK.d.ts.map +1 -1
  107. package/lib/typescript/src/Phone.d.ts +2 -1
  108. package/lib/typescript/src/Phone.d.ts.map +1 -1
  109. package/lib/typescript/src/Press.d.ts.map +1 -1
  110. package/lib/typescript/src/Radio.d.ts.map +1 -1
  111. package/lib/typescript/src/Scroll.d.ts.map +1 -1
  112. package/lib/typescript/src/Tab.d.ts +2 -1
  113. package/lib/typescript/src/Tab.d.ts.map +1 -1
  114. package/lib/typescript/src/Text.d.ts.map +1 -1
  115. package/lib/typescript/src/TextInput.d.ts +8 -1
  116. package/lib/typescript/src/TextInput.d.ts.map +1 -1
  117. package/lib/typescript/src/regions.d.ts +14 -1
  118. package/lib/typescript/src/regions.d.ts.map +1 -1
  119. package/lib/typescript/src/shadows.d.ts +2 -2
  120. package/lib/typescript/src/shadows.d.ts.map +1 -1
  121. package/package.json +1 -1
  122. package/src/Accordion.tsx +1 -0
  123. package/src/Badge.tsx +1 -1
  124. package/src/Button.tsx +81 -7
  125. package/src/Checkbox.tsx +1 -13
  126. package/src/Divider.tsx +1 -10
  127. package/src/EasyIn.tsx +1 -22
  128. package/src/FlatList.tsx +1 -6
  129. package/src/FlatPanel.tsx +1 -9
  130. package/src/Grid.tsx +1 -18
  131. package/src/InputField.tsx +1 -14
  132. package/src/Line.tsx +13 -5
  133. package/src/Load.tsx +59 -2
  134. package/src/Numeral.tsx +115 -31
  135. package/src/PanelRK.tsx +1 -6
  136. package/src/Phone.tsx +100 -73
  137. package/src/Press.tsx +1 -6
  138. package/src/Radio.tsx +1 -15
  139. package/src/Scroll.tsx +1 -13
  140. package/src/Tab.tsx +216 -15
  141. package/src/Text.tsx +21 -8
  142. package/src/TextInput.tsx +1 -24
  143. package/src/regions.ts +19 -4
  144. package/src/shadows.ts +1 -24
package/src/Phone.tsx CHANGED
@@ -4,96 +4,124 @@ import { MText } from "./Text";
4
4
  import { aa3phone } from "./common";
5
5
  import { MTextInput } from "./TextInput";
6
6
  import { codesMap } from "./regions";
7
+
7
8
  export enum PhoneType {
8
9
  ANY = "ANY",
9
10
  MOBILE = "MOBILE",
10
11
  LAND = "LAND"
11
- }
12
+ };
13
+
12
14
  export interface PhoneRaw {
13
- aa2: string
14
- code: number
15
- nn: string
16
- example?: string
17
- }
15
+ aa2: string;
16
+ code: number;
17
+ nn: string;
18
+ example?: string;
19
+ };
20
+
18
21
  export interface PhoneUtil {
19
- regisons: () => string[]
20
- flag: (code: string) => string
22
+ regisons: () => string[];
23
+ flag: (code: string) => string;
21
24
  /**
22
25
  * @param phone
23
26
  * @returns
24
27
  */
25
- parseRaw: (phone: string) => PhoneRaw | null
28
+ parseRaw: (phone: string) => PhoneRaw | null;
29
+
26
30
  /**
27
31
  * @param code
28
32
  * @param phone
29
33
  * @returns
30
34
  */
31
- parseRawByCountryCode: (code: string, phone: string) => PhoneRaw | null
35
+ parseRawByCountryCode: (code: string, phone: string) => PhoneRaw | null;
36
+
32
37
  /**
33
38
  * @param code
34
39
  * @param phone
35
40
  * @returns
36
41
  */
37
- pretty: (phone: string, phoneType?: PhoneType) => string
42
+ pretty: (phone: string, phoneType?: PhoneType) => string;
38
43
  }
44
+
39
45
  function checkList(item: AA3, phoneType: PhoneType) {
40
- const regexlist: RegExp[] = []; const phonelenghts = item.phone_number_lengths; const beginwiths = item.mobile_begin_with; const isNotOnlyMobile = phoneType === PhoneType.MOBILE;
46
+ const regexlist: RegExp[] = []
47
+ const phonelenghts = item.phone_number_lengths
48
+ const beginwiths = item.mobile_begin_with
49
+ const isNotOnlyMobile = phoneType === PhoneType.MOBILE
50
+
41
51
  if (phonelenghts.length && beginwiths.length) {
42
52
  phonelenghts.forEach(pl => {
43
- beginwiths.forEach(bw => { const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]{${pl - (bw as number).toString().length}}$`); regexlist.push(r); })
53
+ beginwiths.forEach(bw => {
54
+ const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]{${pl - (bw as number).toString().length}}$`)
55
+ regexlist.push(r)
56
+ })
44
57
  })
45
58
  } else if (!phonelenghts.length && beginwiths.length) {
46
59
  beginwiths.forEach(bw => {
47
- const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]`); regexlist.push(r);
60
+ const r = new RegExp(`^${item.countryCode}${isNotOnlyMobile ? bw : `[0-9]{${bw.toString().length}}`}[0-9]`)
61
+ regexlist.push(r)
48
62
  })
49
63
  } else if (phonelenghts.length && !beginwiths.length) {
50
64
  phonelenghts.forEach(pl => {
51
- const r = new RegExp(`^${item.countryCode}[0-9]{${pl}}$`); regexlist.push(r);
65
+ const r = new RegExp(`^${item.countryCode}[0-9]{${pl}}$`)
66
+ regexlist.push(r)
52
67
  })
53
68
  } else {
54
- const r = new RegExp(`^${item.countryCode}[0-9]`); regexlist.push(r);
69
+ const r = new RegExp(`^${item.countryCode}[0-9]`)
70
+ regexlist.push(r)
55
71
  }
56
72
  return regexlist
57
73
  }
74
+
58
75
  interface AA3 {
59
76
  countryCode: number;
60
77
  mobile_begin_with?: number[];
61
78
  phone_number_lengths?: number[];
62
79
  flag: string;
63
- }
80
+ };
81
+
64
82
  interface AA2 {
65
83
  aa2: string;
66
84
  flag: string;
67
- }
85
+ };
86
+
68
87
  class Phone {
69
88
  private supportAa2s: AA2[] = [];
70
- static new() { return new Phone(); }
89
+
90
+ static new() {
91
+ return new Phone();
92
+ }
93
+
71
94
  setRegions(vals: string[] = []) {
72
95
  try {
73
96
  vals.forEach(k => {
74
97
  if (aa3phone[k]) {
75
- this.supportAa2s.push({ aa2: k, flag: this.itemAa3ByAa2(k).flag });
76
- };
77
- });
98
+ this.supportAa2s.push({ aa2: k, flag: this.itemAa3ByAa2(k).flag })
99
+ }
100
+ })
78
101
  } catch (error) {
102
+
79
103
  }
80
104
  return this;
81
105
  }
106
+
82
107
  get supportsIat2(): AA2[] {
83
108
  return this.supportAa2s;
84
109
  }
110
+
85
111
  formatRaw(raw: PhoneRaw, noPlusPrefix: boolean = false) {
86
- return `${noPlusPrefix ? "" : "+"}${raw.code}${raw.nn}`
112
+ return `${noPlusPrefix ? "" : "+"}${raw.code}${raw.nn}`;
87
113
  }
114
+
88
115
  private itemAa3ByAa2(aa2: string): AA3 | null {
89
116
  const item: AA3 = aa3phone[aa2];
90
117
  return item ? item : null;
91
118
  }
119
+
92
120
  private check(aa2: string, fullPn: string, phoneType: PhoneType = PhoneType.MOBILE): PhoneRaw | null {
93
- const item: AA3 | null = this.itemAa3ByAa2(aa2);
94
- const regexlist = checkList(item, phoneType);
121
+ const item: AA3 | null = this.itemAa3ByAa2(aa2)
122
+ const regexlist = checkList(item, phoneType)
95
123
  if (regexlist.map(k => k.test(fullPn)).filter(k => k).length > 0) {
96
- const line = `${item.mobile_begin_with.length ? item.mobile_begin_with[item.mobile_begin_with.length - 1] : ""}${"512312387612638131123"}`;
124
+ const line = `${item.mobile_begin_with.length ? item.mobile_begin_with[item.mobile_begin_with.length - 1] : ""}${"512312387612638131123"}`
97
125
  return ({
98
126
  aa2: aa2,
99
127
  code: item.countryCode,
@@ -101,64 +129,80 @@ class Phone {
101
129
  example: line.substring(0, item.phone_number_lengths.length ? item.phone_number_lengths[item.mobile_begin_with.length - 1] : line.length)
102
130
  });
103
131
  }
132
+
104
133
  return null;
105
134
  }
135
+
106
136
  parseRaw(fullPn: string, phoneType?: PhoneType): PhoneRaw | null {
107
137
  try {
108
138
  const pn = (fullPn || "").replace(/\D/g, "").replace(/ /g, "");
109
139
  const aa2s = Object.keys(aa3phone);
140
+
110
141
  let index = 0;
111
142
  let raw: PhoneRaw | null = null;
143
+
112
144
  for (index = 0; index < aa2s.length; index++) {
113
145
  raw = this.check(aa2s[index], pn, phoneType);
146
+
114
147
  if (raw) {
115
148
  break;
116
149
  }
117
150
  }
151
+
118
152
  return raw;
119
153
  } catch (error) {
120
154
  return null;
121
155
  }
122
156
  }
157
+
123
158
  parseRawInput(aa2: string, nn: string, phoneType?: PhoneType): PhoneRaw | null {
124
159
  try {
125
160
  const item: AA3 | null = this.itemAa3ByAa2(aa2);
126
161
  if (!item) {
127
162
  return null;
128
- };
163
+ }
164
+
129
165
  const fullPn = `${item.countryCode}${nn}`;
130
166
  return this.check(aa2, fullPn, phoneType);
131
167
  } catch (error) {
132
168
  return null;
133
169
  }
134
170
  }
171
+
135
172
  placeholder(aa2: string): string {
136
173
  try {
137
174
  const item: AA3 | null = this.itemAa3ByAa2(aa2);
138
175
  if (!item) {
139
176
  return "";
140
177
  }
178
+
141
179
  const line = `${item.mobile_begin_with.length ? item.mobile_begin_with[item.mobile_begin_with.length - 1] : ""}${"512312387612638131123"}`;
180
+
142
181
  return line.substring(0, item.phone_number_lengths.length ? item.phone_number_lengths[item.phone_number_lengths.length - 1] : line.length);
143
182
  } catch (error) {
144
183
  return "";
145
184
  }
146
185
  }
186
+
147
187
  private mask(lenght: number, pt: string, txt: string, rmt: string): string {
148
188
  if (rmt.length === 0 || txt.length >= lenght) {
149
- return txt
189
+ return txt;
150
190
  }
151
191
  const c = pt.at(0);
152
192
  const v = rmt.at(0);
193
+
153
194
  if (c != "#") {
154
195
  txt += c;
155
196
  } else {
156
197
  txt += v;
157
198
  rmt = rmt.split("").filter((_, i) => i != 0).join("");
158
199
  }
200
+
159
201
  pt = pt.split("").filter((_, i) => i != 0).join("");
160
- return this.mask(lenght, pt, txt, rmt)
202
+
203
+ return this.mask(lenght, pt, txt, rmt);
161
204
  }
205
+
162
206
  prettyMaskWoc(aa2: string, nn: string) {
163
207
  try {
164
208
  const item = aa3phone[aa2];
@@ -168,6 +212,7 @@ class Phone {
168
212
  return "";
169
213
  }
170
214
  }
215
+
171
216
  prettyMask(aa2: string, nn: string) {
172
217
  try {
173
218
  const item = aa3phone[aa2];
@@ -178,12 +223,13 @@ class Phone {
178
223
  }
179
224
  }
180
225
  }
226
+
181
227
  export const phoneUtil: PhoneUtil = (() => {
182
228
  function regisons() {
183
- return Object.keys(codesMap)
229
+ return Object.keys(codesMap);
184
230
  }
185
231
  function flag(code: string) {
186
- return aa3phone[code]?.flag
232
+ return aa3phone[code]?.flag;
187
233
  }
188
234
  /**
189
235
  * @param phone
@@ -191,9 +237,9 @@ export const phoneUtil: PhoneUtil = (() => {
191
237
  */
192
238
  function parseRaw(phone: string, phoneType?: PhoneType): PhoneRaw | null {
193
239
  try {
194
- return Phone.new().parseRaw(phone, phoneType)
240
+ return Phone.new().parseRaw(phone, phoneType);
195
241
  } catch (error) {
196
- return null
242
+ return null;
197
243
  }
198
244
  }
199
245
  /**
@@ -203,55 +249,36 @@ export const phoneUtil: PhoneUtil = (() => {
203
249
  */
204
250
  function parseRawByCountryCode(code: string, phone: string, phoneType?: PhoneType): PhoneRaw | null {
205
251
  try {
206
- return Phone.new().parseRawInput(code, phone, phoneType)
252
+ return Phone.new().parseRawInput(code, phone, phoneType);
207
253
  } catch (error) {
208
- return null
254
+ return null;
209
255
  }
210
256
  }
211
257
  function pretty(phone: string, phoneType?: PhoneType): string {
212
258
  try {
213
- const raw = Phone.new().parseRaw(phone.replace(/\D/g, ""), phoneType || PhoneType.ANY)
214
- return Phone.new().prettyMask(raw.aa2, raw.nn)
259
+ const raw = Phone.new().parseRaw(phone.replace(/\D/g, ""), phoneType || PhoneType.ANY);
260
+ return Phone.new().prettyMask(raw.aa2, raw.nn);
215
261
  } catch (error) {
216
- return ""
262
+ return "";
217
263
  }
218
264
  }
219
265
  return { regisons, flag, parseRaw, parseRawByCountryCode, pretty };
220
266
  })();
267
+
221
268
  interface MPhoneInputProps {
222
- containerStyle?: StyleProp<ViewStyle>
223
- phoneStyle?: StyleProp<TextStyle>
224
- placeholder?: string
225
- disabled?: boolean
226
- noPlusPrefix?: boolean
227
- regions?: Array<keyof typeof codesMap>
228
- phoneType?: PhoneType
229
- code: string
230
- value: any
231
- onChangeCountry: (regions: string[], active?: string) => void
232
- onChange: (value: string) => void
233
- onBlur: () => void
234
- }
235
- export function MPhoneInput(props: MPhoneInputProps) {
236
- const [init, setInit] = React.useState<boolean>(false);
237
- const [focus, setFocus] = React.useState<boolean>(false);
238
- const [raw, setRaw] = React.useState<PhoneRaw & { pretty: string, flag: any }>({ aa2: "", nn: "", code: 0, pretty: "", flag: "" });
239
- function onChangeCountryCode(v: string, isReset?: boolean) {
240
- try {
241
- setRaw(vals => { const item = ({ ...vals, aa2: v, nn: isReset ? "" : vals.nn, code: aa3phone[props.code]?.countryCode, flag: aa3phone[props.code]?.flag, example: Phone.new().setRegions(props.regions).placeholder(v) }); item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; });
242
- } catch (error) {
243
- }
244
- }
245
- function onChangeNn(v: string) {
246
- try {
247
- const value = String(v).replace(/\D/g, "");
248
- setRaw(vals => { const item = { ...vals, nn: value }; item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; });
249
- } catch (error) {
269
+ containerStyle?: StyleProp<ViewStyle>;
270
+ phoneStyle?: StyleProp<TextStyle>;
271
+ placeholder?: string;
272
+ disabled?: boolean;
273
+ noPlusPrefix?: boolean;
274
+ regions?: Array<keyof typeof codesMap>;
275
+ phoneType?: PhoneType;
276
+ keyboardType?: 'default' | 'number-pad' | 'decimal-pad' | 'numeric' | 'email-address' | 'phone-pad' | 'url';
277
+ code: string;
278
+ value: any;
279
+ onChangeCountry: (regions: string[], active?: string) => void;
280
+ onChange: (value: string) => void;
281
+ onBlur: () => void;
282
+ };
250
283
 
251
- }
252
- }
253
- React.useEffect(() => { if (init) { const instance = Phone.new().setRegions(props.regions); const rawResponse = instance.parseRawInput(raw.aa2, raw.nn, props.phoneType); if (rawResponse) { const a = instance.formatRaw(rawResponse, props.noPlusPrefix); props.onChange(a); } else if (props.onChange) { props.onChange(""); } } }, [init, focus, raw, props.regions?.length]);
254
- React.useEffect(() => { if (init && !focus) { const rawResponse = Phone.new().setRegions(props.regions).parseRaw(props.value, props.phoneType); if (rawResponse) { const item: PhoneRaw & { pretty: string, flag: any } = { ...rawResponse, pretty: "", flag: aa3phone[rawResponse.aa2]?.flag }; item.pretty = Phone.new().prettyMaskWoc(rawResponse.aa2, raw.nn); setRaw(item); } else { onChangeCountryCode(props.code); } if (rawResponse?.nn == raw?.nn && props.code !== raw.aa2) { onChangeCountryCode(props.code, true); } } }, [init, focus, props.code, props.value]);
255
- React.useEffect(() => { setInit(true); }, []);
256
- return (<View style={[{ flex: 1, height: 45, maxHeight: 45, display: "flex", flexDirection: "row", borderWidth: 1, borderColor: "#dadce0" }, props.containerStyle]}><TouchableHighlight style={{ flex: 1, maxWidth: 55, display: "flex", justifyContent: "center", alignItems: "center", borderRightWidth: 1, borderRightColor: "#dadce0", backgroundColor: "white" }} onPress={() => props.onChangeCountry(Phone.new().setRegions(props.regions).supportsIat2.map(k => k.aa2), raw.aa2)}><MText style={{ textAlign: "center", fontSize: 23 }}>{raw.flag || "🏁"}</MText></TouchableHighlight><View style={{ flex: 1, maxWidth: 55, padding: 5, display: "flex", justifyContent: "center", alignItems: "center", backgroundColor: "white", borderRightWidth: 1, borderRightColor: "#dadce0" }}><MText style={{ color: "black", textAlign: "center", padding: 5, fontWeight: "500" }}>+{raw?.code}</MText></View><MTextInput style={[{ flex: 1, color: "black", borderWidth: 0, borderRadius: 0, minHeight: 43, height: 43 }, props.phoneStyle]} value={raw.pretty} autoFocus={false} maxLength={Phone.new().prettyMaskWoc(raw.aa2, raw.example)?.length} placeholder={props.placeholder} onChangeText={onChangeNn} onFocus={() => setFocus(true)} onBlur={() => setFocus(false)} /></View>);
257
- }
284
+ export function MPhoneInput({ keyboardType = "phone-pad", ...props }: MPhoneInputProps) { const [init, setInit] = React.useState<boolean>(false); const [focus, setFocus] = React.useState<boolean>(false); const [raw, setRaw] = React.useState<PhoneRaw & { pretty: string, flag: any }>({ aa2: "", nn: "", code: 0, pretty: "", flag: "" }); function onChangeCountryCode(v: string, isReset?: boolean) { try { setRaw(vals => { const item = ({ ...vals, aa2: v, nn: isReset ? "" : vals.nn, code: aa3phone[props.code]?.countryCode, flag: aa3phone[props.code]?.flag, example: Phone.new().setRegions(props.regions).placeholder(v) }); item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; }); } catch (error) { } } function onChangeNn(v: string) { try { const value = String(v).replace(/\D/g, ""); setRaw(vals => { const item = { ...vals, nn: value }; item.pretty = Phone.new().prettyMaskWoc(item.aa2, item.nn); return item; }); } catch (error) { } } React.useEffect(() => { if (init) { const instance = Phone.new().setRegions(props.regions); const rawResponse = instance.parseRawInput(raw.aa2, raw.nn, props.phoneType); if (rawResponse) { const a = instance.formatRaw(rawResponse, props.noPlusPrefix); props.onChange(a); } else if (props.onChange) { props.onChange(""); } } }, [init, focus, raw, props.regions?.length]); React.useEffect(() => { if (init && !focus) { const rawResponse = Phone.new().setRegions(props.regions).parseRaw(props.value, props.phoneType); if (rawResponse) { const item: PhoneRaw & { pretty: string, flag: any } = { ...rawResponse, pretty: "", flag: aa3phone[rawResponse.aa2]?.flag }; item.pretty = Phone.new().prettyMaskWoc(rawResponse.aa2, raw.nn); setRaw(item); } else { onChangeCountryCode(props.code); } if (rawResponse?.nn == raw?.nn && props.code !== raw.aa2) { onChangeCountryCode(props.code, true); } } }, [init, focus, props.code, props.value]); React.useEffect(() => { setInit(true); }, []); return (<View style={[{ flex: 1, height: 45, maxHeight: 45, display: "flex", flexDirection: "row", borderWidth: 1, borderColor: "#dadce0" }, props.containerStyle]}><TouchableHighlight style={{ flex: 1, maxWidth: 55, display: "flex", justifyContent: "center", alignItems: "center", borderRightWidth: 1, borderRightColor: "#dadce0", backgroundColor: "white" }} onPress={() => props.onChangeCountry(Phone.new().setRegions(props.regions).supportsIat2.map(k => k.aa2), raw.aa2)}><MText style={{ textAlign: "center", fontSize: 23 }}>{raw.flag || "🏁"}</MText></TouchableHighlight><View style={{ flex: 1, maxWidth: 55, padding: 5, display: "flex", justifyContent: "center", alignItems: "center", backgroundColor: "white", borderRightWidth: 1, borderRightColor: "#dadce0" }}><MText style={{ color: "black", textAlign: "center", padding: 5, fontWeight: "500" }}>+{raw?.code}</MText></View><MTextInput style={[{ flex: 1, color: "black", borderWidth: 0, borderRadius: 0, minHeight: 43, height: 43 }, props.phoneStyle]} value={raw.pretty} keyboardType={keyboardType} placeholder={props.placeholder} maxLength={Phone.new().prettyMaskWoc(raw.aa2, raw.example)?.length} onChangeText={onChangeNn} onFocus={() => setFocus(true)} onBlur={() => setFocus(false)} /></View>) }
package/src/Press.tsx CHANGED
@@ -1,6 +1 @@
1
- import React, { ReactNode } from "react";
2
- import { Pressable, PressableProps } from "react-native";
3
- interface MPressProps extends PressableProps {
4
- children: ReactNode;
5
- };
6
- export function MPress({ children, ...props }: MPressProps) {return (<Pressable {...props}>{children}</Pressable>)}
1
+ import React, { ReactNode } from "react"; import { Pressable, PressableProps } from "react-native"; interface MPressProps extends PressableProps { children: ReactNode; }; export function MPress({ children, ...props }: MPressProps) { return (<Pressable {...props}>{children}</Pressable>); }
package/src/Radio.tsx CHANGED
@@ -1,15 +1 @@
1
- import React, { ReactNode } from "react";
2
- import { TextStyle, TouchableHighlight, TouchableHighlightProps, View } from "react-native";
3
- import { MText } from "./Text";
4
- interface MRadioProps extends TouchableHighlightProps {
5
- name?: string;
6
- activeValue?: string | number | boolean;
7
- value: string | number | boolean;
8
- size?: number;
9
- color: string;
10
- label?: string;
11
- labelStyle?: TextStyle;
12
- onChange?: (values: string | number | boolean, checked: boolean, name?: string) => void;
13
- children?: ReactNode;
14
- };
15
- export function MRadio({ name = "", activeValue, value, color, label, size = 26, labelStyle, style, onChange, ...props }: MRadioProps) { const checked = value == activeValue; return (<TouchableHighlight activeOpacity={0.85}{...props} onPress={() => { if (onChange) { onChange(checked ? "" : value, !checked, name); }; }} underlayColor="transparent" style={[{ flex: 1 }, style]}><View style={{ display: "flex", flexDirection: "row", alignItems: "center", minHeight: size }}><View style={{ padding: 4, width: size, height: size, borderRadius: size, borderWidth: 1, borderColor: color, backgroundColor: "white", display: "flex", justifyContent: "center", alignItems: "center" }} ><View style={{ width: size - 8, height: size - 8, backgroundColor: checked ? color : "white", borderRadius: size }} /></View><MText style={[{ flex: 1, fontSize: 15, paddingLeft: 5 }, labelStyle]}>{label}</MText></View></TouchableHighlight>) }
1
+ import React, { ReactNode } from "react"; import { TextStyle, TouchableHighlight, TouchableHighlightProps, View } from "react-native"; import { MText } from "./Text"; interface MRadioProps extends TouchableHighlightProps { name?: string; activeValue?: string | number | boolean; value: string | number | boolean; size?: number; color: string; label?: string; labelStyle?: TextStyle; onChange?: (values: string | number | boolean, checked: boolean, name?: string) => void; children?: ReactNode; }; export function MRadio({ name = "", activeValue, value, color, label, size = 26, labelStyle, style, onChange, ...props }: MRadioProps) { const checked = value == activeValue; return (<TouchableHighlight activeOpacity={0.85} {...props} onPress={() => { if (onChange) { onChange(checked ? "" : value, !checked, name); } }} underlayColor="transparent" style={[{ flex: 1 }, style]}><View style={{ display: "flex", flexDirection: "row", alignItems: "center", minHeight: size }}><View style={{ padding: 4, width: size, height: size, borderRadius: size, borderWidth: 1, borderColor: color, backgroundColor: "white", display: "flex", justifyContent: "center", alignItems: "center" }}><View style={{ width: size - 8, height: size - 8, backgroundColor: checked ? color : "white", borderRadius: size }} /></View><MText style={[{ flex: 1, fontSize: 15, paddingLeft: 5 }, labelStyle]}>{label}</MText></View></TouchableHighlight>) }
package/src/Scroll.tsx CHANGED
@@ -1,13 +1 @@
1
- import React, { forwardRef, ReactNode } from "react";
2
- import { RefreshControl, ScrollView, StyleProp, ViewStyle, ScrollViewProps } from "react-native";
3
- export const styleMSVerticalCenter = {
4
- justifyContent: "center"
5
- } as any;
6
- interface MScrollProps extends ScrollViewProps {
7
- name?: string;
8
- contentContainerStyle?: StyleProp<ViewStyle>;
9
- isRefreshing?: boolean;
10
- onRefresh?: () => void;
11
- children?: ReactNode;
12
- };
13
- export const MScroll = forwardRef<ScrollView, MScrollProps>((props, ref) => { return (<ScrollView ref={ref} contentInsetAdjustmentBehavior="automatic" contentContainerStyle={{ flexGrow: 1, backgroundColor: "transparent", paddingBottom: 175, padding: 9, ...(props.contentContainerStyle || {}) as any }} refreshControl={(props.onRefresh ? <RefreshControl refreshing={Boolean(props.isRefreshing)} onRefresh={props.onRefresh} /> : <React.Fragment></React.Fragment>)}>{props.children}</ScrollView>); })
1
+ import React, { forwardRef, ReactNode } from "react"; import { RefreshControl, ScrollView, StyleProp, ViewStyle, ScrollViewProps } from "react-native"; export const styleMSVerticalCenter = { justifyContent: "center" } as any; interface MScrollProps extends ScrollViewProps { name?: string; contentContainerStyle?: StyleProp<ViewStyle>; isRefreshing?: boolean; onRefresh?: () => void; children?: ReactNode; }; export const MScroll = forwardRef<ScrollView, MScrollProps>((props, ref) => { return (<ScrollView ref={ref} contentInsetAdjustmentBehavior="automatic" contentContainerStyle={{ flexGrow: 1, backgroundColor: "transparent", paddingBottom: 175, padding: 9, ...(props.contentContainerStyle || {}) as any }} refreshControl={(props.onRefresh && (<RefreshControl refreshing={Boolean(props.isRefreshing)} onRefresh={props.onRefresh} /> ))}>{props.children}</ScrollView> ) })