AndroidTextInput: support using commands instead of setNativeProps (native change)

Summary:
In AndroidTextInput, support codegen'd ViewCommands in native and add three commands that will eventually replace usage of setNativeProps on Android.

TextInput will use these commands in a future diff.

Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D18612150

fbshipit-source-id: 5d427040686e8c5ab504dd845bc8ef863f558c35
This commit is contained in:
Joshua Gross
2019-11-27 12:55:48 -08:00
committed by Facebook Github Bot
parent 98b8a17645
commit 7ab5eb4caf
4 changed files with 105 additions and 24 deletions
@@ -18,11 +18,13 @@ import type {
Float,
Int32,
WithDefault,
} from 'react-native/Libraries/Types/CodegenTypes';
} from '../../Types/CodegenTypes';
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
import type {TextStyleProp, ViewStyleProp} from '../../StyleSheet/StyleSheet';
import type {ColorValue} from '../../StyleSheet/StyleSheetTypes';
import {requireNativeComponent} from 'react-native';
import codegenNativeCommands from '../../Utilities/codegenNativeCommands';
import * as React from 'react';
export type KeyboardType =
// Cross Platform
@@ -534,6 +536,33 @@ export type NativeProps = $ReadOnly<{|
text?: ?string,
|}>;
type NativeType = HostComponent<NativeProps>;
interface NativeCommands {
+focus: (viewRef: React.ElementRef<NativeType>) => void;
+blur: (viewRef: React.ElementRef<NativeType>) => void;
+setMostRecentEventCount: (
viewRef: React.ElementRef<NativeType>,
eventCount: Int32,
) => void;
+setTextAndSelection: (
viewRef: React.ElementRef<NativeType>,
mostRecentEventCount: Int32,
value: ?string, // in theory this is nullable
start: Int32,
end: Int32,
) => void;
}
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: [
'focus',
'blur',
'setMostRecentEventCount',
'setTextAndSelection',
],
});
const AndroidTextInputNativeComponent: HostComponent<NativeProps> = requireNativeComponent<NativeProps>(
'AndroidTextInput',
);