mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Add RootTag to New Commands Codegen
Summary: Adds support for `RootTag` in the new codegen for Native Component Commands. Changelog: [Internal] Reviewed By: TheSavior Differential Revision: D21169371 fbshipit-source-id: 3b25433f3328e9c04cfe45bb176fc06d63559f14
This commit is contained in:
committed by
Facebook GitHub Bot
parent
310b0c3af5
commit
4d9fa4b08e
@@ -21,12 +21,18 @@ export type CommandsFunctionTypeParamAnnotation = $ReadOnly<{|
|
||||
|}>;
|
||||
|
||||
export type CommandsTypeAnnotation =
|
||||
| ReservedFunctionValueTypeAnnotation
|
||||
| BooleanTypeAnnotation
|
||||
| Int32TypeAnnotation
|
||||
| DoubleTypeAnnotation
|
||||
| FloatTypeAnnotation
|
||||
| StringTypeAnnotation;
|
||||
|
||||
type ReservedFunctionValueTypeAnnotation = $ReadOnly<{|
|
||||
type: 'ReservedFunctionValueTypeAnnotation',
|
||||
name: ReservedFunctionValueTypeName,
|
||||
|}>;
|
||||
|
||||
export type DoubleTypeAnnotation = $ReadOnly<{|
|
||||
type: 'DoubleTypeAnnotation',
|
||||
|}>;
|
||||
|
||||
+48
-8
@@ -102,7 +102,17 @@ NS_ASSUME_NONNULL_END
|
||||
`.trim();
|
||||
|
||||
function getObjCParamType(param: CommandsFunctionTypeParamAnnotation): string {
|
||||
switch (param.typeAnnotation.type) {
|
||||
const {typeAnnotation} = param;
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return 'double';
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return 'BOOL';
|
||||
case 'DoubleTypeAnnotation':
|
||||
@@ -114,7 +124,7 @@ function getObjCParamType(param: CommandsFunctionTypeParamAnnotation): string {
|
||||
case 'StringTypeAnnotation':
|
||||
return 'NSString *';
|
||||
default:
|
||||
(param.typeAnnotation.type: empty);
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error('Received invalid param type annotation');
|
||||
}
|
||||
}
|
||||
@@ -122,7 +132,17 @@ function getObjCParamType(param: CommandsFunctionTypeParamAnnotation): string {
|
||||
function getObjCExpectedKindParamType(
|
||||
param: CommandsFunctionTypeParamAnnotation,
|
||||
): string {
|
||||
switch (param.typeAnnotation.type) {
|
||||
const {typeAnnotation} = param;
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return '[NSNumber class]';
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return '[NSNumber class]';
|
||||
case 'DoubleTypeAnnotation':
|
||||
@@ -134,7 +154,7 @@ function getObjCExpectedKindParamType(
|
||||
case 'StringTypeAnnotation':
|
||||
return '[NSString class]';
|
||||
default:
|
||||
(param.typeAnnotation.type: empty);
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error('Received invalid param type annotation');
|
||||
}
|
||||
}
|
||||
@@ -142,7 +162,17 @@ function getObjCExpectedKindParamType(
|
||||
function getReadableExpectedKindParamType(
|
||||
param: CommandsFunctionTypeParamAnnotation,
|
||||
): string {
|
||||
switch (param.typeAnnotation.type) {
|
||||
const {typeAnnotation} = param;
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return 'double';
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return 'boolean';
|
||||
case 'DoubleTypeAnnotation':
|
||||
@@ -154,7 +184,7 @@ function getReadableExpectedKindParamType(
|
||||
case 'StringTypeAnnotation':
|
||||
return 'string';
|
||||
default:
|
||||
(param.typeAnnotation.type: empty);
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error('Received invalid param type annotation');
|
||||
}
|
||||
}
|
||||
@@ -163,7 +193,17 @@ function getObjCRightHandAssignmentParamType(
|
||||
param: CommandsFunctionTypeParamAnnotation,
|
||||
index: number,
|
||||
): string {
|
||||
switch (param.typeAnnotation.type) {
|
||||
const {typeAnnotation} = param;
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return `[(NSNumber *)arg${index} doubleValue]`;
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return `[(NSNumber *)arg${index} boolValue]`;
|
||||
case 'DoubleTypeAnnotation':
|
||||
@@ -175,7 +215,7 @@ function getObjCRightHandAssignmentParamType(
|
||||
case 'StringTypeAnnotation':
|
||||
return `(NSString *)arg${index}`;
|
||||
default:
|
||||
(param.typeAnnotation.type: empty);
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error('Received invalid param type annotation');
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -153,7 +153,17 @@ function generatePropCasesString(
|
||||
}
|
||||
|
||||
function getCommandArgJavaType(param, index) {
|
||||
switch (param.typeAnnotation.type) {
|
||||
const {typeAnnotation} = param;
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return `args.getDouble(${index})`;
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return `args.getBoolean(${index})`;
|
||||
case 'DoubleTypeAnnotation':
|
||||
@@ -165,8 +175,8 @@ function getCommandArgJavaType(param, index) {
|
||||
case 'StringTypeAnnotation':
|
||||
return `args.getString(${index})`;
|
||||
default:
|
||||
(param.typeAnnotation.type: empty);
|
||||
throw new Error('Receieved invalid typeAnnotation');
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.type}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
-2
@@ -125,7 +125,17 @@ function generatePropsString(component: ComponentShape, imports) {
|
||||
}
|
||||
|
||||
function getCommandArgJavaType(param) {
|
||||
switch (param.typeAnnotation.type) {
|
||||
const {typeAnnotation} = param;
|
||||
|
||||
switch (typeAnnotation.type) {
|
||||
case 'ReservedFunctionValueTypeAnnotation':
|
||||
switch (typeAnnotation.name) {
|
||||
case 'RootTag':
|
||||
return 'double';
|
||||
default:
|
||||
(typeAnnotation.name: empty);
|
||||
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
||||
}
|
||||
case 'BooleanTypeAnnotation':
|
||||
return 'boolean';
|
||||
case 'DoubleTypeAnnotation':
|
||||
@@ -137,7 +147,7 @@ function getCommandArgJavaType(param) {
|
||||
case 'StringTypeAnnotation':
|
||||
return 'String';
|
||||
default:
|
||||
(param.typeAnnotation.type: empty);
|
||||
(typeAnnotation.type: empty);
|
||||
throw new Error('Receieved invalid typeAnnotation');
|
||||
}
|
||||
}
|
||||
|
||||
+16
@@ -1475,6 +1475,22 @@ const COMMANDS_AND_PROPS: SchemaType = {
|
||||
},
|
||||
],
|
||||
commands: [
|
||||
{
|
||||
name: 'handleRootTag',
|
||||
optional: false,
|
||||
typeAnnotation: {
|
||||
type: 'FunctionTypeAnnotation',
|
||||
params: [
|
||||
{
|
||||
name: 'rootTag',
|
||||
typeAnnotation: {
|
||||
type: 'ReservedFunctionValueTypeAnnotation',
|
||||
name: 'RootTag',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'hotspotUpdate',
|
||||
optional: false,
|
||||
|
||||
+22
-1
@@ -208,6 +208,7 @@ Map {
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol RCTCommandNativeComponentViewProtocol <NSObject>
|
||||
- (void)handleRootTag:(double)rootTag;
|
||||
- (void)hotspotUpdate:(NSInteger)x y:(NSInteger)y;
|
||||
@end
|
||||
|
||||
@@ -216,7 +217,27 @@ RCT_EXTERN inline void RCTCommandNativeComponentHandleCommand(
|
||||
NSString const *commandName,
|
||||
NSArray const *args)
|
||||
{
|
||||
if ([commandName isEqualToString:@\\"hotspotUpdate\\"]) {
|
||||
if ([commandName isEqualToString:@\\"handleRootTag\\"]) {
|
||||
#if RCT_DEBUG
|
||||
if ([args count] != 1) {
|
||||
RCTLogError(@\\"%@ command %@ received %d arguments, expected %d.\\", @\\"CommandNativeComponent\\", commandName, (int)[args count], 1);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
NSObject *arg0 = args[0];
|
||||
#if RCT_DEBUG
|
||||
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @\\"double\\", @\\"CommandNativeComponent\\", commandName, @\\"1st\\")) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
double rootTag = [(NSNumber *)arg0 doubleValue];
|
||||
|
||||
[componentView handleRootTag:rootTag];
|
||||
return;
|
||||
}
|
||||
|
||||
if ([commandName isEqualToString:@\\"hotspotUpdate\\"]) {
|
||||
#if RCT_DEBUG
|
||||
if ([args count] != 2) {
|
||||
RCTLogError(@\\"%@ command %@ received %d arguments, expected %d.\\", @\\"CommandNativeComponent\\", commandName, (int)[args count], 2);
|
||||
|
||||
+3
@@ -266,6 +266,9 @@ public class CommandNativeComponentManagerDelegate<T extends View, U extends Bas
|
||||
|
||||
public void receiveCommand(CommandNativeComponentManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
|
||||
switch (commandName) {
|
||||
case \\"handleRootTag\\":
|
||||
viewManager.handleRootTag(view, args.getDouble(0));
|
||||
break;
|
||||
case \\"hotspotUpdate\\":
|
||||
viewManager.hotspotUpdate(view, args.getInt(0), args.getInt(1));
|
||||
break;
|
||||
|
||||
+1
@@ -145,6 +145,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
public interface CommandNativeComponentManagerInterface<T extends View> {
|
||||
void setAccessibilityHint(T view, @Nullable String value);
|
||||
void handleRootTag(T view, double rootTag);
|
||||
void hotspotUpdate(T view, int x, int y);
|
||||
}
|
||||
",
|
||||
|
||||
+4
@@ -227,6 +227,10 @@ export const __INTERNAL_VIEW_CONFIG = CommandNativeComponentViewConfig;
|
||||
export default nativeComponentName;
|
||||
|
||||
export const Commands = {
|
||||
handleRootTag(ref, rootTag) {
|
||||
dispatchCommand(ref, \\"handleRootTag\\", [rootTag]);
|
||||
},
|
||||
|
||||
hotspotUpdate(ref, x, y) {
|
||||
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
|
||||
}
|
||||
|
||||
+3
-1
@@ -837,6 +837,7 @@ const codegenNativeCommands = require('codegenNativeCommands');
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {Int32, Double, Float} from 'CodegenTypes';
|
||||
import type {RootTag} from 'RCTExport';
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
import type {HostComponent} from 'react-native';
|
||||
|
||||
@@ -849,6 +850,7 @@ export type ModuleProps = $ReadOnly<{|
|
||||
type NativeType = HostComponent<ModuleProps>;
|
||||
|
||||
interface NativeCommands {
|
||||
+handleRootTag: (viewRef: React.ElementRef<NativeType>, rootTag: RootTag) => void;
|
||||
+hotspotUpdate: (viewRef: React.ElementRef<NativeType>, x: Int32, y: Int32) => void;
|
||||
+scrollTo: (
|
||||
viewRef: React.ElementRef<NativeType>,
|
||||
@@ -860,7 +862,7 @@ interface NativeCommands {
|
||||
}
|
||||
|
||||
export const Commands = codegenNativeCommands<NativeCommands>({
|
||||
supportedCommands: ['hotspotUpdate', 'scrollTo'],
|
||||
supportedCommands: ['handleRootTag', 'hotspotUpdate', 'scrollTo'],
|
||||
});
|
||||
|
||||
export default (codegenNativeComponent<ModuleProps>(
|
||||
|
||||
+16
@@ -2336,6 +2336,22 @@ Object {
|
||||
"components": Object {
|
||||
"Module": Object {
|
||||
"commands": Array [
|
||||
Object {
|
||||
"name": "handleRootTag",
|
||||
"optional": false,
|
||||
"typeAnnotation": Object {
|
||||
"params": Array [
|
||||
Object {
|
||||
"name": "rootTag",
|
||||
"typeAnnotation": Object {
|
||||
"name": "RootTag",
|
||||
"type": "ReservedFunctionValueTypeAnnotation",
|
||||
},
|
||||
},
|
||||
],
|
||||
"type": "FunctionTypeAnnotation",
|
||||
},
|
||||
},
|
||||
Object {
|
||||
"name": "hotspotUpdate",
|
||||
"optional": false,
|
||||
|
||||
@@ -47,6 +47,12 @@ function buildCommandSchema(property, types: TypeMap) {
|
||||
let returnType;
|
||||
|
||||
switch (type) {
|
||||
case 'RootTag':
|
||||
returnType = {
|
||||
type: 'ReservedFunctionValueTypeAnnotation',
|
||||
name: 'RootTag',
|
||||
};
|
||||
break;
|
||||
case 'BooleanTypeAnnotation':
|
||||
returnType = {
|
||||
type: 'BooleanTypeAnnotation',
|
||||
|
||||
Reference in New Issue
Block a user