react-native-controlled-input 0.11.0 → 0.12.0

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.
@@ -1,8 +1,11 @@
1
1
  "use strict";
2
2
 
3
- import { forwardRef, memo, useImperativeHandle, useRef } from 'react';
3
+ import { forwardRef, memo, useImperativeHandle, useLayoutEffect, useRef } from 'react';
4
4
  import { Platform, processColor, StyleSheet } from 'react-native';
5
- import ControlledInputViewNativeComponent, { Commands } from './ControlledInputViewNativeComponent';
5
+ // TextInputState is not exported from the public react-native package.
6
+ // eslint-disable-next-line @react-native/no-deep-imports -- integrate with ScrollView keyboard dismissal
7
+ import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
8
+ import ControlledInputViewNativeComponent from './ControlledInputViewNativeComponent';
6
9
  import { jsx as _jsx } from "react/jsx-runtime";
7
10
  // All style props that Android handles via Compose instead of the native View layer
8
11
  const androidComposeHandledKeys = ['color', 'fontSize', 'fontFamily', 'padding', 'paddingVertical', 'paddingHorizontal', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight', 'borderWidth', 'borderRadius', 'borderColor', 'backgroundColor'];
@@ -18,11 +21,30 @@ function resolveAndroidComposeViewPadding(flat) {
18
21
  export const ControlledInputView = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(({
19
22
  style,
20
23
  onTextChange,
24
+ onFocus,
25
+ onBlur,
21
26
  selectionColor,
22
27
  placeholderTextColor,
23
28
  ...rest
24
29
  }, ref) => {
25
30
  const nativeRef = useRef(null);
31
+ const isNativePlatform = Platform.OS === 'ios' || Platform.OS === 'android';
32
+ useLayoutEffect(() => {
33
+ if (!isNativePlatform) {
34
+ return;
35
+ }
36
+ const node = nativeRef.current;
37
+ if (node == null) {
38
+ return;
39
+ }
40
+ TextInputState.registerInput(node);
41
+ return () => {
42
+ TextInputState.unregisterInput(node);
43
+ if (TextInputState.currentlyFocusedInput() === node) {
44
+ TextInputState.blurTextInput(node);
45
+ }
46
+ };
47
+ }, [isNativePlatform]);
26
48
  const flattenedStyle = StyleSheet.flatten(style) ?? {};
27
49
  let viewStyle;
28
50
  let inputStyle;
@@ -59,18 +81,26 @@ export const ControlledInputView = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(({
59
81
  onTextChange(e.nativeEvent.value);
60
82
  }
61
83
  };
84
+ const handleFocus = e => {
85
+ if (isNativePlatform) {
86
+ TextInputState.focusInput(nativeRef.current);
87
+ }
88
+ onFocus?.(e);
89
+ };
90
+ const handleBlur = e => {
91
+ if (isNativePlatform) {
92
+ TextInputState.blurInput(nativeRef.current);
93
+ }
94
+ onBlur?.(e);
95
+ };
62
96
  useImperativeHandle(ref, () => ({
63
97
  blur: () => {
64
- if (!nativeRef.current) return;
65
- if (Platform.OS === 'ios' || Platform.OS === 'android') {
66
- Commands.blur(nativeRef.current);
67
- }
98
+ if (!nativeRef.current || !isNativePlatform) return;
99
+ TextInputState.blurTextInput(nativeRef.current);
68
100
  },
69
101
  focus: () => {
70
- if (!nativeRef.current) return;
71
- if (Platform.OS === 'ios' || Platform.OS === 'android') {
72
- Commands.focus(nativeRef.current);
73
- }
102
+ if (!nativeRef.current || !isNativePlatform) return;
103
+ TextInputState.focusTextInput(nativeRef.current);
74
104
  }
75
105
  }));
76
106
  return /*#__PURE__*/_jsx(ControlledInputViewNativeComponent, {
@@ -80,6 +110,8 @@ export const ControlledInputView = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(({
80
110
  style: viewStyle,
81
111
  inputStyle: inputStyle,
82
112
  onTextChange: handleTextChange,
113
+ onFocus: handleFocus,
114
+ onBlur: handleBlur,
83
115
  ref: nativeRef
84
116
  });
85
117
  }));
@@ -1 +1 @@
1
- {"version":3,"names":["forwardRef","memo","useImperativeHandle","useRef","Platform","processColor","StyleSheet","ControlledInputViewNativeComponent","Commands","jsx","_jsx","androidComposeHandledKeys","resolveAndroidComposeViewPadding","flat","padding","paddingTop","paddingVertical","paddingBottom","paddingLeft","paddingHorizontal","paddingRight","ControlledInputView","style","onTextChange","selectionColor","placeholderTextColor","rest","ref","nativeRef","flattenedStyle","flatten","viewStyle","inputStyle","OS","Object","fromEntries","entries","filter","k","includes","hasPadding","some","v","color","fontSize","fontFamily","borderWidth","borderRadius","borderColor","backgroundColor","iosViewStyle","hasTextStyle","undefined","handleTextChange","e","nativeEvent","value","blur","current","focus","displayName"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SACEA,UAAU,EACVC,IAAI,EACJC,mBAAmB,EACnBC,MAAM,QAED,OAAO;AACd,SACEC,QAAQ,EACRC,YAAY,EACZC,UAAU,QAIL,cAAc;AACrB,OAAOC,kCAAkC,IACvCC,QAAQ,QAGH,sCAAsC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AA0B9C;AACA,MAAMC,yBAAyB,GAAG,CAChC,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,iBAAiB,CAClB;AAED,SAASC,gCAAgCA,CAACC,IAAyB,EAAE;EACnE,MAAMC,OAAO,GAAGD,IAAI,CAACC,OAAO,IAAI,CAAC;EAEjC,OAAO;IACLC,UAAU,EAAEF,IAAI,CAACE,UAAU,IAAIF,IAAI,CAACG,eAAe,IAAIF,OAAO;IAC9DG,aAAa,EAAEJ,IAAI,CAACI,aAAa,IAAIJ,IAAI,CAACG,eAAe,IAAIF,OAAO;IACpEI,WAAW,EAAEL,IAAI,CAACK,WAAW,IAAIL,IAAI,CAACM,iBAAiB,IAAIL,OAAO;IAClEM,YAAY,EAAEP,IAAI,CAACO,YAAY,IAAIP,IAAI,CAACM,iBAAiB,IAAIL;EAC/D,CAAC;AACH;AAEA,OAAO,MAAMO,mBAAmB,gBAAGpB,IAAI,cACrCD,UAAU,CACR,CACE;EAAEsB,KAAK;EAAEC,YAAY;EAAEC,cAAc;EAAEC,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AqB;AAEvD,cAAc,sCAAsC","ignoreList":[]}
1
+ {"version":3,"names":["forwardRef","memo","useImperativeHandle","useLayoutEffect","useRef","Platform","processColor","StyleSheet","TextInputState","ControlledInputViewNativeComponent","jsx","_jsx","androidComposeHandledKeys","resolveAndroidComposeViewPadding","flat","padding","paddingTop","paddingVertical","paddingBottom","paddingLeft","paddingHorizontal","paddingRight","ControlledInputView","style","onTextChange","onFocus","onBlur","selectionColor","placeholderTextColor","rest","ref","nativeRef","isNativePlatform","OS","node","current","registerInput","unregisterInput","currentlyFocusedInput","blurTextInput","flattenedStyle","flatten","viewStyle","inputStyle","Object","fromEntries","entries","filter","k","includes","hasPadding","some","v","color","fontSize","fontFamily","borderWidth","borderRadius","borderColor","backgroundColor","iosViewStyle","hasTextStyle","undefined","handleTextChange","e","nativeEvent","value","handleFocus","focusInput","handleBlur","blurInput","blur","focus","focusTextInput","displayName"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SACEA,UAAU,EACVC,IAAI,EACJC,mBAAmB,EACnBC,eAAe,EACfC,MAAM,QAED,OAAO;AACd,SACEC,QAAQ,EACRC,YAAY,EACZC,UAAU,QAIL,cAAc;AACrB;AACA;AACA,OAAOC,cAAc,MAAM,4DAA4D;AACvF,OAAOC,kCAAkC,MAGlC,sCAAsC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAiC9C;AACA,MAAMC,yBAAyB,GAAG,CAChC,OAAO,EACP,UAAU,EACV,YAAY,EACZ,SAAS,EACT,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,aAAa,EACb,cAAc,EACd,aAAa,EACb,cAAc,EACd,aAAa,EACb,iBAAiB,CAClB;AAED,SAASC,gCAAgCA,CAACC,IAAyB,EAAE;EACnE,MAAMC,OAAO,GAAGD,IAAI,CAACC,OAAO,IAAI,CAAC;EAEjC,OAAO;IACLC,UAAU,EAAEF,IAAI,CAACE,UAAU,IAAIF,IAAI,CAACG,eAAe,IAAIF,OA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-1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,cAAc,EAGpB,MAAM,cAAc,CAAC;AACtB,OAA2C,EAEzC,KAAK,WAAW,EAEjB,MAAM,sCAAsC,CAAC;AAE9C,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,KAAK,uBAAuB,GAAG,IAAI,CACjC,cAAc,EACZ,cAAc,GACd,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,aAAa,GACb,sBAAsB,GACtB,gBAAgB,CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,WAAW,EACX,YAAY,GAAG,cAAc,GAAG,MAAM,uBAAuB,CAC9D,GACC,uBAAuB,GAAG;IACxB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AA+BJ,eAAO,MAAM,mBAAmB;mBAhCb,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;0DAwHzC,CAAC;AAIF,cAAc,sCAAsC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAQA,OAAO,EAIL,KAAK,cAAc,EAGpB,MAAM,cAAc,CAAC;AAItB,OAA2C,EACzC,KAAK,WAAW,EAEjB,MAAM,sCAAsC,CAAC;AAE9C,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,KAAK,uBAAuB,GAAG,IAAI,CACjC,cAAc,EACZ,cAAc,GACd,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,aAAa,GACb,sBAAsB,GACtB,gBAAgB,CACnB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,WAAW,EACX,YAAY,GAAG,cAAc,GAAG,MAAM,uBAAuB,CAC9D,GACC,uBAAuB,GAAG;IACxB,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAsCJ,eAAO,MAAM,mBAAmB;mBAvCb,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI;0DA0KzC,CAAC;AAIF,cAAc,sCAAsC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-controlled-input",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "React Native Controlled Inputative Controlled Input",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
package/src/index.tsx CHANGED
@@ -2,6 +2,7 @@ import {
2
2
  forwardRef,
3
3
  memo,
4
4
  useImperativeHandle,
5
+ useLayoutEffect,
5
6
  useRef,
6
7
  type ElementRef,
7
8
  } from 'react';
@@ -13,8 +14,10 @@ import {
13
14
  type ViewStyle,
14
15
  type TextStyle,
15
16
  } from 'react-native';
17
+ // TextInputState is not exported from the public react-native package.
18
+ // eslint-disable-next-line @react-native/no-deep-imports -- integrate with ScrollView keyboard dismissal
19
+ import TextInputState from 'react-native/Libraries/Components/TextInput/TextInputState';
16
20
  import ControlledInputViewNativeComponent, {
17
- Commands,
18
21
  type NativeProps,
19
22
  type TextChangeEvent,
20
23
  } from './ControlledInputViewNativeComponent';
@@ -43,6 +46,13 @@ export type ControlledInputViewProps = Omit<
43
46
  onTextChange?: (value: string) => void;
44
47
  };
45
48
 
49
+ type ControlledInputFocusEvent = Parameters<
50
+ NonNullable<NativeProps['onFocus']>
51
+ >[0];
52
+ type ControlledInputBlurEvent = Parameters<
53
+ NonNullable<NativeProps['onBlur']>
54
+ >[0];
55
+
46
56
  // All style props that Android handles via Compose instead of the native View layer
47
57
  const androidComposeHandledKeys = [
48
58
  'color',
@@ -75,12 +85,43 @@ function resolveAndroidComposeViewPadding(flat: Record<string, any>) {
75
85
  export const ControlledInputView = memo(
76
86
  forwardRef<ControlledInputViewRef, ControlledInputViewProps>(
77
87
  (
78
- { style, onTextChange, selectionColor, placeholderTextColor, ...rest },
88
+ {
89
+ style,
90
+ onTextChange,
91
+ onFocus,
92
+ onBlur,
93
+ selectionColor,
94
+ placeholderTextColor,
95
+ ...rest
96
+ },
79
97
  ref
80
98
  ) => {
81
99
  const nativeRef =
82
100
  useRef<ElementRef<typeof ControlledInputViewNativeComponent>>(null);
83
101
 
102
+ const isNativePlatform =
103
+ Platform.OS === 'ios' || Platform.OS === 'android';
104
+
105
+ useLayoutEffect(() => {
106
+ if (!isNativePlatform) {
107
+ return;
108
+ }
109
+
110
+ const node = nativeRef.current;
111
+ if (node == null) {
112
+ return;
113
+ }
114
+
115
+ TextInputState.registerInput(node);
116
+
117
+ return () => {
118
+ TextInputState.unregisterInput(node);
119
+ if (TextInputState.currentlyFocusedInput() === node) {
120
+ TextInputState.blurTextInput(node);
121
+ }
122
+ };
123
+ }, [isNativePlatform]);
124
+
84
125
  const flattenedStyle = (StyleSheet.flatten(style) ?? {}) as TextStyle;
85
126
 
86
127
  let viewStyle: ViewStyle;
@@ -132,18 +173,28 @@ export const ControlledInputView = memo(
132
173
  }
133
174
  };
134
175
 
176
+ const handleFocus = (e: ControlledInputFocusEvent) => {
177
+ if (isNativePlatform) {
178
+ TextInputState.focusInput(nativeRef.current);
179
+ }
180
+ onFocus?.(e);
181
+ };
182
+
183
+ const handleBlur = (e: ControlledInputBlurEvent) => {
184
+ if (isNativePlatform) {
185
+ TextInputState.blurInput(nativeRef.current);
186
+ }
187
+ onBlur?.(e);
188
+ };
189
+
135
190
  useImperativeHandle(ref, () => ({
136
191
  blur: () => {
137
- if (!nativeRef.current) return;
138
- if (Platform.OS === 'ios' || Platform.OS === 'android') {
139
- Commands.blur(nativeRef.current);
140
- }
192
+ if (!nativeRef.current || !isNativePlatform) return;
193
+ TextInputState.blurTextInput(nativeRef.current);
141
194
  },
142
195
  focus: () => {
143
- if (!nativeRef.current) return;
144
- if (Platform.OS === 'ios' || Platform.OS === 'android') {
145
- Commands.focus(nativeRef.current);
146
- }
196
+ if (!nativeRef.current || !isNativePlatform) return;
197
+ TextInputState.focusTextInput(nativeRef.current);
147
198
  },
148
199
  }));
149
200
 
@@ -155,6 +206,8 @@ export const ControlledInputView = memo(
155
206
  style={viewStyle}
156
207
  inputStyle={inputStyle}
157
208
  onTextChange={handleTextChange}
209
+ onFocus={handleFocus}
210
+ onBlur={handleBlur}
158
211
  ref={nativeRef}
159
212
  />
160
213
  );
@@ -19,3 +19,19 @@ declare module 'react-native/Libraries/Utilities/codegenNativeComponent' {
19
19
  componentName: string
20
20
  ): HostComponent<T>;
21
21
  }
22
+
23
+ declare module 'react-native/Libraries/Components/TextInput/TextInputState' {
24
+ import type { HostInstance } from 'react-native';
25
+
26
+ const TextInputState: {
27
+ registerInput(textField: HostInstance): void;
28
+ unregisterInput(textField: HostInstance): void;
29
+ focusInput(textField: HostInstance | null): void;
30
+ blurInput(textField: HostInstance | null): void;
31
+ focusTextInput(textField: HostInstance | null): void;
32
+ blurTextInput(textField: HostInstance | null): void;
33
+ currentlyFocusedInput(): HostInstance | null;
34
+ };
35
+
36
+ export default TextInputState;
37
+ }