From 0e4de896802b15d121c58056e8ba0fb45218263b Mon Sep 17 00:00:00 2001 From: Phil Chung Date: Wed, 3 Apr 2024 12:46:20 -0600 Subject: [PATCH] fix: remove touch passthrough --- .../rivereactnative/RiveReactNativeView.kt | 9 ---- .../RiveReactNativeViewManager.kt | 21 -------- ios/RiveReactNativeView.swift | 51 ------------------- ios/RiveReactNativeViewManager.m | 4 -- ios/RiveReactNativeViewManager.swift | 16 ------ src/Rive.tsx | 42 --------------- src/types.ts | 4 -- 7 files changed, 147 deletions(-) diff --git a/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt b/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt index e3e0f2f..c3d50ba 100644 --- a/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt +++ b/android/src/main/java/com/rivereactnative/RiveReactNativeView.kt @@ -5,7 +5,6 @@ import androidx.annotation.CallSuper import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.LifecycleOwner -import app.rive.runtime.kotlin.PointerEvents import app.rive.runtime.kotlin.RiveAnimationView import app.rive.runtime.kotlin.controllers.RiveFileController import app.rive.runtime.kotlin.core.* @@ -300,14 +299,6 @@ class RiveReactNativeView(private val context: ThemedReactContext) : FrameLayout } } - fun touchBegan(x: Float, y: Float) { - riveAnimationView.artboardRenderer?.pointerEvent(PointerEvents.POINTER_DOWN, x, y) - } - - fun touchEnded(x: Float, y: Float) { - riveAnimationView.artboardRenderer?.pointerEvent(PointerEvents.POINTER_UP, x, y) - } - fun setTextRunValue(textRunName: String, textValue: String) { try { riveAnimationView.artboardRenderer?.activeArtboard?.textRun(textRunName)?.text = textValue; diff --git a/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt b/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt index c730240..ab8924a 100644 --- a/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt +++ b/android/src/main/java/com/rivereactnative/RiveReactNativeViewManager.kt @@ -71,27 +71,6 @@ class RiveReactNativeViewManager : SimpleViewManager() { } } - // Touch Events - - "touchBegan" -> { - args?.let { - val x: Double = it.getDouble(0) - val y: Double = it.getDouble(1) - view.run { - this.touchBegan(x.toFloat(), y.toFloat()) - } - } - } - "touchEnded" -> { - args?.let { - val x: Double = it.getDouble(0) - val y: Double = it.getDouble(1) - view.run { - this.touchEnded(x.toFloat(), y.toFloat()) - } - } - } - // Text Run "setTextRunValue" -> { diff --git a/ios/RiveReactNativeView.swift b/ios/RiveReactNativeView.swift index 7422236..b77f2a3 100644 --- a/ios/RiveReactNativeView.swift +++ b/ios/RiveReactNativeView.swift @@ -295,57 +295,6 @@ class RiveReactNativeView: RCTView, RivePlayerDelegate, RiveStateMachineDelegate // TODO: implement if in Android } - // MARK: - Touch Events - - @objc open func touchBegan(_ location: CGPoint) { - handleTouch(location: location) { machine, abLocation in - guard let riveView = viewModel?.riveView else { fatalError("No RiveView") } - guard let artboard = viewModel?.riveModel?.artboard else { fatalError("Malformed RiveModel") } - if (riveView.stateMachineDelegate?.touchBegan != nil) { - riveView.stateMachineDelegate?.touchBegan?(onArtboard: artboard, atLocation: abLocation) - } - } - } - - @objc open func touchMoved(_ location: CGPoint) { - handleTouch(location: location) { machine, abLocation in - guard let riveView = viewModel?.riveView else { fatalError("No RiveView") } - guard let artboard = viewModel?.riveModel?.artboard else { fatalError("Malformed RiveModel") } - riveView.stateMachineDelegate?.touchMoved?(onArtboard: artboard, atLocation: abLocation) - } - } - - @objc open func touchEnded(_ location: CGPoint) { - handleTouch(location: location) { machine, abLocation in - guard let riveView = viewModel?.riveView else { fatalError("No RiveView") } - guard let artboard = viewModel?.riveModel?.artboard else { fatalError("Malformed RiveModel") } - riveView.stateMachineDelegate?.touchEnded?(onArtboard: artboard, atLocation: abLocation) - } - } - - @objc open func touchCancelled(_ location: CGPoint) { - handleTouch(location: location) { machine, abLocation in - guard let riveView = viewModel?.riveView else { fatalError("No RiveView") } - guard let artboard = viewModel?.riveModel?.artboard else { fatalError("Malformed RiveModel") } - riveView.stateMachineDelegate?.touchCancelled?(onArtboard: artboard, atLocation: abLocation) - } - } - - private func handleTouch(location: CGPoint, action: (RiveStateMachineInstance, CGPoint)->Void) { - if let viewModel = viewModel, let riveView = viewModel.riveView { - let artboardLocation = riveView.artboardLocation( - fromTouchLocation: location, - inArtboard: viewModel.riveModel!.artboard!.bounds(), - fit: viewModel.fit, - alignment: viewModel.alignment - ) - if let stateMachine = viewModel.riveModel?.stateMachine { - viewModel.play() - action(stateMachine, artboardLocation) - } - } - } - // MARK: - Error Handling private func onRNRiveError(_ rnRiveError: BaseRNRiveError) { diff --git a/ios/RiveReactNativeViewManager.m b/ios/RiveReactNativeViewManager.m index fd01b27..371693d 100644 --- a/ios/RiveReactNativeViewManager.m +++ b/ios/RiveReactNativeViewManager.m @@ -27,10 +27,6 @@ @interface RCT_EXTERN_MODULE(RiveReactNativeViewManager, RCTViewManager) RCT_EXTERN_METHOD(fireState:(nonnull NSNumber *)node stateMachineName:(nonnull NSString)stateMachineName inputName:(nonnull NSString)inputName) RCT_EXTERN_METHOD(setBooleanState:(nonnull NSNumber *)node stateMachineName:(nonnull NSString)stateMachineName inputName:(nonnull NSString)inputName value:(BOOL)value) RCT_EXTERN_METHOD(setNumberState:(nonnull NSNumber *)node stateMachineName:(nonnull NSString)stateMachineName inputName:(nonnull NSString)inputName value:(nonnull NSNumber *)value) -RCT_EXTERN_METHOD(touchBegan:(nonnull NSNumber *)node x:(nonnull NSNumber*)x y:(nonnull NSNumber*)y) -RCT_EXTERN_METHOD(touchMoved:(nonnull NSNumber *)node x:(nonnull NSNumber*)x y:(nonnull NSNumber*)y) -RCT_EXTERN_METHOD(touchEnded:(nonnull NSNumber *)node x:(nonnull NSNumber*)x y:(nonnull NSNumber*)y) -RCT_EXTERN_METHOD(touchCancelled:(nonnull NSNumber *)node x:(nonnull NSNumber*)x y:(nonnull NSNumber*)y) RCT_EXTERN_METHOD(setTextRunValue:(nonnull NSNumber *)node textRunName:(nonnull NSString)textRunName textRunValue:(nonnull NSString)textRunValue) @end diff --git a/ios/RiveReactNativeViewManager.swift b/ios/RiveReactNativeViewManager.swift index ac801e5..54933ab 100644 --- a/ios/RiveReactNativeViewManager.swift +++ b/ios/RiveReactNativeViewManager.swift @@ -57,22 +57,6 @@ class RiveReactNativeViewManager: RCTViewManager { } } - @objc func touchBegan(_ node: NSNumber, x: NSNumber, y: NSNumber) { - DispatchQueue.main.async { - let view = self.bridge.uiManager.view(forReactTag: node) as! RiveReactNativeView - let touch = CGPoint(x: x.doubleValue, y: y.doubleValue) - view.touchBegan(touch) - } - } - - @objc func touchEnded(_ node: NSNumber, x: NSNumber, y: NSNumber) { - DispatchQueue.main.async { - let view = self.bridge.uiManager.view(forReactTag: node) as! RiveReactNativeView - let touch = CGPoint(x: x.doubleValue, y: y.doubleValue) - view.touchEnded(touch) - } - } - @objc func setTextRunValue(_ node: NSNumber, textRunName: String, textRunValue: String) { DispatchQueue.main.async { let view = self.bridge.uiManager.view(forReactTag: node) as! RiveReactNativeView diff --git a/src/Rive.tsx b/src/Rive.tsx index 6be8d0e..3076035 100644 --- a/src/Rive.tsx +++ b/src/Rive.tsx @@ -7,8 +7,6 @@ import { NativeSyntheticEvent, StyleSheet, View, - TouchableWithoutFeedback, - GestureResponderEvent, StyleProp, } from 'react-native'; import { @@ -294,33 +292,6 @@ const RiveContainer = React.forwardRef( }, [] ); - - const touchBegan = useCallback( - (x: number, y: number) => { - if (!isNaN(x) && !isNaN(y)) { - UIManager.dispatchViewManagerCommand( - findNodeHandle(riveRef.current), - ViewManagerMethod.touchBegan, - [x, y] - ); - } - }, - [] - ); - - const touchEnded = useCallback( - (x: number, y: number) => { - if (!isNaN(x) && !isNaN(y)) { - UIManager.dispatchViewManagerCommand( - findNodeHandle(riveRef.current), - ViewManagerMethod.touchEnded, - [x, y] - ); - } - }, - [] - ); - const setTextRunValue = useCallback< RiveRef[ViewManagerMethod.setTextRunValue] >((textRunName: string, textValue: string) => { @@ -342,8 +313,6 @@ const RiveContainer = React.forwardRef( pause, stop, reset, - touchBegan, - touchEnded, setTextRunValue, }), [ @@ -353,8 +322,6 @@ const RiveContainer = React.forwardRef( reset, setInputState, fireState, - touchBegan, - touchEnded, setTextRunValue, ] ); @@ -362,14 +329,6 @@ const RiveContainer = React.forwardRef( return ( {children} - - touchBegan(event.nativeEvent.locationX, event.nativeEvent.locationY) - } - onPressOut={(event: GestureResponderEvent) => - touchEnded(event.nativeEvent.locationX, event.nativeEvent.locationY) - } - > ( animationName={animationName} stateMachineName={stateMachineName} /> - ); } diff --git a/src/types.ts b/src/types.ts index 99c6e81..834a2e5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,8 +14,6 @@ export type RiveRef = { pause: () => void; stop: () => void; reset: () => void; - touchBegan: (x: number, y: number) => void; - touchEnded: (x: number, y: number) => void; setTextRunValue: (textRunName: string, value: string) => void; }; @@ -27,8 +25,6 @@ export enum ViewManagerMethod { fireState = 'fireState', setBooleanState = 'setBooleanState', setNumberState = 'setNumberState', - touchBegan = 'touchBegan', - touchEnded = 'touchEnded', setTextRunValue = 'setTextRunValue', }