Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,12 @@ function InternalTextInput(props: TextInputProps): React.Node {
before we can get to the long term breaking change.
*/
if (instance != null) {
// Register the input immediately when the ref is set so that focus()
// can be called from ref callbacks
// Double registering during useLayoutEffect is fine, because the underlying
// state is a Set.
TextInputState.registerInput(instance);

// $FlowFixMe[prop-missing] - See the explanation above.
// $FlowFixMe[unsafe-object-assign]
Object.assign(instance, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const ViewNativeComponent: HostComponent<Props> =
}));

interface NativeCommands {
+focus: () => void;
+blur: () => void;
+focus: (viewRef: HostInstance) => void;
+blur: (viewRef: HostInstance) => void;
+hotspotUpdate: (viewRef: HostInstance, x: number, y: number) => void;
+setPressed: (viewRef: HostInstance, pressed: boolean) => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import '@react-native/fantom/src/setUpDefaultReactNativeEnvironment';
import type {HostInstance} from 'react-native';

import ReactNativeElement from '../../../../src/private/webapis/dom/nodes/ReactNativeElement';
import TextInput from '../../../Components/TextInput/TextInput';
import TextInputState from '../../../Components/TextInput/TextInputState';
import View from '../../../Components/View/View';
import ReactFabricHostComponent from '../ReactFabricHostComponent';
Expand Down Expand Up @@ -48,7 +49,7 @@ describe('ReactFabricPublicInstance', () => {
const nodeRef = createRef<HostInstance>();

Fantom.runTask(() => {
root.render(<View ref={nodeRef} />);
root.render(<TextInput ref={nodeRef} />);
});

const node = nullthrows(nodeRef.current);
Expand All @@ -73,7 +74,7 @@ describe('ReactFabricPublicInstance', () => {
const ref = createRef<HostInstance>();

Fantom.runTask(() => {
root.render(<View ref={ref} />);
root.render(<TextInput ref={ref} />);
});

const node = nullthrows(ref.current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ import type {InstanceHandle} from './internals/NodeInternals';
import type ReactNativeDocument from './ReactNativeDocument';

import TextInputState from '../../../../../Libraries/Components/TextInput/TextInputState';
import {Commands as ViewCommands} from '../../../../../Libraries/Components/View/ViewNativeComponent';
import {create as createAttributePayload} from '../../../../../Libraries/ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload';
import warnForStyleProps from '../../../../../Libraries/ReactNative/ReactFabricPublicInstance/warnForStyleProps';
import * as ReactNativeFeatureFlags from '../../../featureflags/ReactNativeFeatureFlags';
import {
getNativeElementReference,
getPublicInstanceFromInstanceHandle,
Expand Down Expand Up @@ -140,11 +142,19 @@ class ReactNativeElement extends ReadOnlyElement implements NativeMethods {
*/

blur(): void {
TextInputState.blurTextInput(this);
if (TextInputState.isTextInput(this)) {
TextInputState.blurTextInput(this);
} else if (ReactNativeFeatureFlags.enableImperativeFocus()) {
ViewCommands.blur(this);
}
}

focus() {
TextInputState.focusTextInput(this);
if (TextInputState.isTextInput(this)) {
TextInputState.focusTextInput(this);
} else if (ReactNativeFeatureFlags.enableImperativeFocus()) {
ViewCommands.focus(this);
}
}

measure(callback: MeasureOnSuccessCallback) {
Expand Down
Loading