Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ - (void)callNativeMethodToRemoveOverlays
[_view removeOverlays];
}

- (void)fireLagacyStyleEvent
{
RNTMyNativeViewEventEmitter::OnLegacyStyleEvent value = {"Legacy Style Event Fired."};

std::static_pointer_cast<const RNTMyNativeViewEventEmitter>(_eventEmitter)->onLegacyStyleEvent(value);
}

@end

Class<RCTComponentViewProtocol> RNTMyNativeViewCls(void)
Expand Down
13 changes: 12 additions & 1 deletion packages/rn-tester/NativeComponentExample/js/MyNativeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ export default function MyNativeView(props: {}): React.Node {
console.log(event.nativeEvent.latLons);
console.log(event.nativeEvent.multiArrays);
}}
onLegacyStyleEvent={event => {
console.log(event.nativeEvent.string);
}}
/>
<Text style={{color: 'red'}}>Legacy View</Text>
<RNTMyLegacyNativeView
Expand Down Expand Up @@ -218,7 +221,15 @@ export default function MyNativeView(props: {}): React.Node {
}
}}
/>

<Button
title="Fire Legacy Style Event"
onPress={() => {
RNTMyNativeViewCommands.fireLagacyStyleEvent(
// $FlowFixMe[incompatible-call]
ref.current,
);
}}
/>
<Text style={{color: 'green', textAlign: 'center'}}>
&gt; Interop Layer Measurements &lt;
</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ type Event = $ReadOnly<{
multiArrays: $ReadOnlyArray<$ReadOnlyArray<Int32>>,
}>;

type LegacyStyleEvent = $ReadOnly<{
string: string,
}>;

type NativeProps = $ReadOnly<{|
...ViewProps,
opacity?: Float,
values: $ReadOnlyArray<Int32>,

// Events
onIntArrayChanged?: ?BubblingEventHandler<Event>,
onLegacyStyleEvent?: ?BubblingEventHandler<
LegacyStyleEvent,
'alternativeLegacyName',
>,
|}>;

export type MyNativeViewType = HostComponent<NativeProps>;
Expand All @@ -57,13 +65,16 @@ interface NativeCommands {
+callNativeMethodToRemoveOverlays: (
viewRef: React.ElementRef<MyNativeViewType>,
) => void;

+fireLagacyStyleEvent: (viewRef: React.ElementRef<MyNativeViewType>) => void;
}

export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: [
'callNativeMethodToChangeBackgroundColor',
'callNativeMethodToAddOverlays',
'callNativeMethodToRemoveOverlays',
'fireLagacyStyleEvent',
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ class MyNativeView(context: ThemedReactContext) : View(context) {
eventDispatcher?.dispatchEvent(event)
}

fun emitLegacyStyleEvent() {
val reactContext = context as ReactContext
val surfaceId = UIManagerHelper.getSurfaceId(reactContext)
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id)
val payload = Arguments.createMap().apply { putString("string", "Legacy Style Event Fired.") }
val event = OnLegacyStyleEvent(surfaceId, id, payload)
eventDispatcher?.dispatchEvent(event)
}

inner class OnIntArrayChangedEvent(
surfaceId: Int,
viewId: Int,
Expand All @@ -133,4 +142,11 @@ class MyNativeView(context: ThemedReactContext) : View(context) {

override fun getEventData() = payload
}

inner class OnLegacyStyleEvent(surfaceId: Int, viewId: Int, private val payload: WritableMap) :
Event<OnLegacyStyleEvent>(surfaceId, viewId) {
override fun getEventName() = "alternativeLegacyName"

override fun getEventData() = payload
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ internal class MyNativeViewManager :
view.removeOverlays()
}

override fun fireLagacyStyleEvent(view: MyNativeView) {
view.emitLegacyStyleEvent()
}

@ReactProp(name = ViewProps.OPACITY, defaultFloat = 1f)
override fun setOpacity(view: MyNativeView, opacity: Float) {
super.setOpacity(view, opacity)
Expand Down