Skip to content

Commit

Permalink
fix: remove touch passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
philter committed Apr 3, 2024
1 parent 4eef109 commit 0e4de89
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,6 @@ class RiveReactNativeViewManager : SimpleViewManager<RiveReactNativeView>() {
}
}

// 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" -> {
Expand Down
51 changes: 0 additions & 51 deletions ios/RiveReactNativeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 0 additions & 4 deletions ios/RiveReactNativeViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 0 additions & 16 deletions ios/RiveReactNativeViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 0 additions & 42 deletions src/Rive.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
NativeSyntheticEvent,
StyleSheet,
View,
TouchableWithoutFeedback,
GestureResponderEvent,
StyleProp,
} from 'react-native';
import {
Expand Down Expand Up @@ -294,33 +292,6 @@ const RiveContainer = React.forwardRef<RiveRef, Props>(
},
[]
);

const touchBegan = useCallback<RiveRef[ViewManagerMethod.touchBegan]>(
(x: number, y: number) => {
if (!isNaN(x) && !isNaN(y)) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(riveRef.current),
ViewManagerMethod.touchBegan,
[x, y]
);
}
},
[]
);

const touchEnded = useCallback<RiveRef[ViewManagerMethod.touchEnded]>(
(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) => {
Expand All @@ -342,8 +313,6 @@ const RiveContainer = React.forwardRef<RiveRef, Props>(
pause,
stop,
reset,
touchBegan,
touchEnded,
setTextRunValue,
}),
[

Check failure on line 318 in src/Rive.tsx

View workflow job for this annotation

GitHub Actions / typecheck-and-lint

Replace `⏎········play,⏎········pause,⏎········stop,⏎········reset,⏎········setInputState,⏎········fireState,⏎········setTextRunValue,⏎······` with `play,·pause,·stop,·reset,·setInputState,·fireState,·setTextRunValue`
Expand All @@ -353,23 +322,13 @@ const RiveContainer = React.forwardRef<RiveRef, Props>(
reset,
setInputState,
fireState,
touchBegan,
touchEnded,
setTextRunValue,
]
);

return (
<View style={[styles.container, style]} ref={ref as any} testID={testID}>
<View style={styles.children}>{children}</View>
<TouchableWithoutFeedback
onPressIn={(event: GestureResponderEvent) =>
touchBegan(event.nativeEvent.locationX, event.nativeEvent.locationY)
}
onPressOut={(event: GestureResponderEvent) =>
touchEnded(event.nativeEvent.locationX, event.nativeEvent.locationY)
}
>
<RiveViewManager

Check failure on line 332 in src/Rive.tsx

View workflow job for this annotation

GitHub Actions / typecheck-and-lint

Replace `··········` with `········`
ref={riveRef}

Check failure on line 333 in src/Rive.tsx

View workflow job for this annotation

GitHub Actions / typecheck-and-lint

Delete `··`
resourceName={resourceName}

Check failure on line 334 in src/Rive.tsx

View workflow job for this annotation

GitHub Actions / typecheck-and-lint

Replace `············` with `··········`
Expand All @@ -390,7 +349,6 @@ const RiveContainer = React.forwardRef<RiveRef, Props>(
animationName={animationName}
stateMachineName={stateMachineName}
/>
</TouchableWithoutFeedback>
</View>
);
}
Expand Down
4 changes: 0 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -27,8 +25,6 @@ export enum ViewManagerMethod {
fireState = 'fireState',
setBooleanState = 'setBooleanState',
setNumberState = 'setNumberState',
touchBegan = 'touchBegan',
touchEnded = 'touchEnded',
setTextRunValue = 'setTextRunValue',
}

Expand Down

0 comments on commit 0e4de89

Please sign in to comment.