private bool TryMakeBubblingEvent(ViewManagerExportedBubblingEventTypeConstantAttribute attribute, MemberInfo memberInfo, Type memberType, IJSValueWriter constantWriter, out Delegate memberValue) { if (null != attribute && null != memberInfo && TryGetEventDataType(memberType, out Type eventDataType)) { var eventName = attribute.EventName ?? "top" + memberInfo.Name; var bubbleName = attribute.BubbleCallbackName ?? "on" + memberInfo.Name; var captureName = attribute.CaptureCallbackName ?? bubbleName + "Capture"; constantWriter.WritePropertyName(eventName); constantWriter.WriteObjectBegin(); constantWriter.WritePropertyName("phasedRegistrationNames"); constantWriter.WriteObjectBegin(); constantWriter.WriteObjectProperty("bubbled", bubbleName); constantWriter.WriteObjectProperty("captured", captureName); constantWriter.WriteObjectEnd(); constantWriter.WriteObjectEnd(); memberValue = MakeEventDelegate(eventName, memberType, eventDataType); return(true); } memberValue = default(Delegate); return(false); }
public static void WriteObject(IJSValueWriter writer, IEnumerable <KeyValuePair <string, JSValue> > value) { writer.WriteObjectBegin(); foreach (var keyValue in value) { writer.WritePropertyName(keyValue.Key); keyValue.Value.WriteTo(writer); } writer.WriteObjectEnd(); }
public static void WriteError( IJSValueWriter writer, string code, string message, IReadOnlyDictionary <string, JSValue> userInfo, string stackTrace) { writer.WriteArrayBegin(); { writer.WriteObjectBegin(); { writer.WritePropertyName(ReactErrorConstants.Code); writer.WriteString(code ?? ReactErrorConstants.DefaultCode); writer.WritePropertyName(ReactErrorConstants.Message); writer.WriteString(message ?? ReactErrorConstants.DefaultMessage); // For consistency with iOS ensure userInfo key exists, even if we null it. // iOS: /React/Base/RCTUtils.m -> RCTJSErrorFromCodeMessageAndNSError writer.WritePropertyName(ReactErrorConstants.UserInfo); if (userInfo == null) { writer.WriteNull(); } else { writer.WriteValue(userInfo); } // Attach a nativeStackWindows string if an exception was passed. // This matches iOS behavior - iOS adds a `nativeStackIOS` property // iOS: /React/Base/RCTUtils.m -> RCTJSErrorFromCodeMessageAndNSError writer.WritePropertyName(ReactErrorConstants.NativeStack); writer.WriteString(stackTrace ?? string.Empty); } writer.WriteObjectEnd(); } writer.WriteArrayEnd(); }
public static void WriteObjectProperty <T>(this IJSValueWriter writer, string name, T value) { writer.WritePropertyName(name); writer.WriteValue(value); }
public static bool WriteProperty <T>(this IJSValueWriter writer, string name, T value) { return(writer.WritePropertyName(name) && writer.WriteValueObject(value)); }