private bool TryExtractEvent(ISymbol symbol, string defaultEventEmitterName, [NotNullWhen(returnValue: true)] out ReactEvent?reactEvent)
        {
            if (TryExtractCallback(symbol, defaultEventEmitterName, ReactTypes.ReactEventAttribute, out var callbackParameters, out var name, out var declaredModuleName))
            {
                reactEvent = new ReactEvent(symbol, callbackParameters, name, declaredModuleName);
                return(true);
            }

            reactEvent = null;
            return(false);
        }
示例#2
0
 internal StatementSyntax AddEvent(ReactEvent evnt)
 {
     // generates:
     //   moduleBuilder.AddInitializer((IReactContext reactContext) =>
     //      module.MyEvent = (ArgType0 arg0, ArgType1 arg1, ...) => new ReactContext(reactContext).EmitJsEvent("eventEmitterName", "eventName", arg0, arg1, ...);
     return(InvocationStatement(
                MemberAccessExpression(ReactNativeNames.ModuleBuilder, ReactNativeNames.AddInitializer),
                ParenthesizedLambdaExpression(
                    parameterList: ParameterList(
                        Parameter(ReactNativeNames.ReactContextLocalName).WithType(ReactTypes.IReactContext.ToTypeSyntax())),
                    block: null,
                    expressionBody: GenerateCallback(evnt, ReactNativeNames.EmitJSEventFunctionName))));
 }