Skip to content
Permalink
Browse files

Support string command arguments

Summary: Support command arguments that are strings

Reviewed By: JoshuaGross

Differential Revision: D16509728

fbshipit-source-id: 003aba66231d204071d043c01cb0781150d0edb9
  • Loading branch information...
TheSavior authored and facebook-github-bot committed Jul 29, 2019
1 parent a174647 commit 0314305e1202e48c74091e15da8574f1b92ce441
@@ -22,7 +22,8 @@ export type CommandsFunctionTypeParamAnnotation = $ReadOnly<{|

export type CommandsTypeAnnotation =
| BooleanTypeAnnotation
| Int32TypeAnnotation;
| Int32TypeAnnotation
| StringTypeAnnotation;

export type BooleanTypeAnnotation = $ReadOnly<{|
type: 'BooleanTypeAnnotation',
@@ -32,6 +33,10 @@ export type Int32TypeAnnotation = $ReadOnly<{|
type: 'Int32TypeAnnotation',
|}>;

export type StringTypeAnnotation = $ReadOnly<{|
type: 'StringTypeAnnotation',
|}>;

export type ObjectPropertyType =
| $ReadOnly<{|
type: 'BooleanTypeAnnotation',
@@ -107,6 +107,8 @@ function getObjCParamType(param: CommandsFunctionTypeParamAnnotation): string {
return 'BOOL';
case 'Int32TypeAnnotation':
return 'NSInteger';
case 'StringTypeAnnotation':
return 'NSString *';
default:
(param.typeAnnotation.type: empty);
throw new Error('Received invalid param type annotation');
@@ -121,6 +123,8 @@ function getObjCExpectedKindParamType(
return '[NSNumber class]';
case 'Int32TypeAnnotation':
return '[NSNumber class]';
case 'StringTypeAnnotation':
return '[NSString class]';
default:
(param.typeAnnotation.type: empty);
throw new Error('Received invalid param type annotation');
@@ -135,6 +139,8 @@ function getReadableExpectedKindParamType(
return 'boolean';
case 'Int32TypeAnnotation':
return 'number';
case 'StringTypeAnnotation':
return 'string';
default:
(param.typeAnnotation.type: empty);
throw new Error('Received invalid param type annotation');
@@ -150,6 +156,8 @@ function getObjCRightHandAssignmentParamType(
return `[(NSNumber *)arg${index} boolValue]`;
case 'Int32TypeAnnotation':
return `[(NSNumber *)arg${index} intValue]`;
case 'StringTypeAnnotation':
return `(NSString *)arg${index}`;
default:
(param.typeAnnotation.type: empty);
throw new Error('Received invalid param type annotation');
@@ -122,6 +122,8 @@ function getCommandArgJavaType(param) {
return 'getBoolean';
case 'Int32TypeAnnotation':
return 'getInt';
case 'StringTypeAnnotation':
return 'getString';
default:
(param.typeAnnotation.type: empty);
throw new Error('Receieved invalid typeAnnotation');
@@ -97,6 +97,8 @@ function getCommandArgJavaType(param) {
return 'boolean';
case 'Int32TypeAnnotation':
return 'int';
case 'StringTypeAnnotation':
return 'String';
default:
(param.typeAnnotation.type: empty);
throw new Error('Receieved invalid typeAnnotation');
@@ -941,6 +941,12 @@ const COMMANDS: SchemaType = {
type: 'Int32TypeAnnotation',
},
},
{
name: 'message',
typeAnnotation: {
type: 'StringTypeAnnotation',
},
},
{
name: 'animated',
typeAnnotation: {
@@ -86,7 +86,7 @@ NS_ASSUME_NONNULL_BEGIN

@protocol CommandNativeComponentViewProtocol <NSObject>
- (void)flashScrollIndicators;
- (void)allTypes:(NSInteger)x animated:(BOOL)animated;
- (void)allTypes:(NSInteger)x message:(NSString *)message animated:(BOOL)animated;
@end

RCT_EXTERN inline void CommandNativeComponentHandleCommand(
@@ -110,8 +110,8 @@ RCT_EXTERN inline void CommandNativeComponentHandleCommand(

if ([commandName isEqualToString:@\\"allTypes\\"]) {
#if RCT_DEBUG
if ([args count] != 2) {
RCTLogError(@\\"%@ command %@ received %d arguments, expected %d.\\", @\\"CommandNativeComponent\\", commandName, (int)[args count], 2);
if ([args count] != 3) {
RCTLogError(@\\"%@ command %@ received %d arguments, expected %d.\\", @\\"CommandNativeComponent\\", commandName, (int)[args count], 3);
return;
}
#endif
@@ -126,13 +126,21 @@ if ([commandName isEqualToString:@\\"allTypes\\"]) {

#if RCT_DEBUG
NSObject *arg1 = args[1];
if (!RCTValidateTypeOfViewCommandArgument(arg1, [NSNumber class], @\\"boolean\\", @\\"CommandNativeComponent\\", commandName, @\\"2nd\\")) {
if (!RCTValidateTypeOfViewCommandArgument(arg1, [NSString class], @\\"string\\", @\\"CommandNativeComponent\\", commandName, @\\"2nd\\")) {
return;
}
#endif
NSString * message = (NSString *)arg1;

#if RCT_DEBUG
NSObject *arg2 = args[2];
if (!RCTValidateTypeOfViewCommandArgument(arg2, [NSNumber class], @\\"boolean\\", @\\"CommandNativeComponent\\", commandName, @\\"3rd\\")) {
return;
}
#endif
BOOL animated = [(NSNumber *)arg1 boolValue];
BOOL animated = [(NSNumber *)arg2 boolValue];

[componentView allTypes:x animated:animated]
[componentView allTypes:x message:message animated:animated]
return;
}

@@ -100,7 +100,7 @@ public class CommandNativeComponentViewManagerDelegate<T extends View> {
viewManager.flashScrollIndicators(view);
break;
case \\"allTypes\\":
viewManager.allTypes(view, args.getInt(0), args.getBoolean(1));
viewManager.allTypes(view, args.getInt(0), args.getString(1), args.getBoolean(2));
break;
}
}
@@ -62,7 +62,7 @@ import android.view.View;
public interface CommandNativeComponentViewManagerInterface<T extends View> {
// No props
void flashScrollIndicators(T view);
void allTypes(T view, int x, boolean animated);
void allTypes(T view, int x, String message, boolean animated);
}
",
}
@@ -152,11 +152,11 @@ export const Commands = {
);
},

allTypes(ref, x, animated) {
allTypes(ref, x, message, animated) {
UIManager.dispatchViewCommand(
findNodeHandle(ref),
UIManager.getViewManagerConfig(\\"CommandNativeComponent\\").Commands.allTypes,
[x, animated]
[x, message, animated]
);
}
};

0 comments on commit 0314305

Please sign in to comment.
You can’t perform that action at this time.