Skip to content

Commit a57de2d

Browse files
dagatsoinerictraut
authored andcommitted
[FIX] onTouchMove on mobile web does not trigger (#1079)
* add onTouchMove handler on View * replace onTouchMove by onResponderMove
1 parent a732419 commit a57de2d

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

samples/RXPTest/src/Tests/ViewTouchTest.tsx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ const _styles = {
4646
backgroundColor: '#eee',
4747
borderColor: 'black',
4848
}),
49+
testContainer4: RX.Styles.createViewStyle({
50+
flex: 1,
51+
height: 150,
52+
margin: 20,
53+
borderWidth: 1,
54+
backgroundColor: '#eee',
55+
borderColor: 'black',
56+
}),
4957
success: RX.Styles.createViewStyle({
5058
borderWidth: 2,
5159
backgroundColor: 'green'
@@ -59,6 +67,10 @@ interface TouchViewState {
5967
view3TouchResponderTestStart: boolean;
6068
view3TouchResponderTestGrant: boolean;
6169
view3TouchResponderTestRelease: boolean;
70+
touchPositionOnPage: {
71+
x: number | null
72+
y: number | null
73+
};
6274
nestedViewTouchTestParent: boolean;
6375
nestedViewTouchTestChild: boolean;
6476
pressEvent?: RX.Types.TouchEvent;
@@ -75,6 +87,10 @@ class ViewTouch extends RX.Component<RX.CommonProps, TouchViewState> {
7587
view3TouchResponderTestStart: false,
7688
view3TouchResponderTestGrant: false,
7789
view3TouchResponderTestRelease: false,
90+
touchPositionOnPage: {
91+
x: null,
92+
y: null
93+
},
7894
nestedViewTouchTestParent: false,
7995
nestedViewTouchTestChild: false,
8096
};
@@ -83,7 +99,7 @@ class ViewTouch extends RX.Component<RX.CommonProps, TouchViewState> {
8399
private static getTouchEventText(touchEvent?: RX.Types.TouchEvent): string {
84100
if (touchEvent) {
85101
return 'altKey = ' + touchEvent.altKey +
86-
' changedTouches.length = ' + touchEvent.changedTouches.length +
102+
' changedTouches.length = ' + (touchEvent.changedTouches && touchEvent.changedTouches.length) +
87103
' ctrlKey = ' + touchEvent.ctrlKey +
88104
' metaKey = ' + touchEvent.metaKey +
89105
' shiftKey = ' + touchEvent.shiftKey +
@@ -171,6 +187,27 @@ class ViewTouch extends RX.Component<RX.CommonProps, TouchViewState> {
171187
}}
172188
/>
173189
</RX.View>
190+
<RX.View style={ _styles.explainTextContainer }>
191+
<RX.Text style={ _styles.explainText }>
192+
{ 'When touching this view, it will display the page coordinates of the touch position.' }
193+
</RX.Text>
194+
</RX.View>
195+
<RX.View
196+
style={ _styles.testContainer4 }
197+
onResponderMove={ e => {
198+
const touch = e.touches[0];
199+
if (touch) {
200+
this.setState({ touchPositionOnPage: {
201+
x: Math.round(touch.pageX),
202+
y: Math.round(touch.pageY)
203+
}});
204+
}
205+
}}
206+
>
207+
<RX.Text style={ _styles.labelText }>
208+
{ `Touch position on page: x: ${this.state.touchPositionOnPage.x} y: ${this.state.touchPositionOnPage.y}`}
209+
</RX.Text>
210+
</RX.View>
174211
</RX.View>
175212
);
176213
}

src/web/View.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RX.Vi
357357
onMouseLeave: this.props.onMouseLeave,
358358
onMouseOver: this.props.onMouseOver,
359359
onMouseMove: this.props.onMouseMove,
360+
// Weird things happens: ReactXP.Types.Touch is not assignable to React.Touch
361+
onTouchMove: this.props.onResponderMove as React.HTMLAttributes<any>['onTouchMove'],
360362
draggable: this.props.onDragStart ? true : undefined,
361363
onDragStart: this.props.onDragStart,
362364
onDrag: this.props.onDrag,

0 commit comments

Comments
 (0)