Skip to content
Merged
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
39 changes: 38 additions & 1 deletion samples/RXPTest/src/Tests/ViewTouchTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ const _styles = {
backgroundColor: '#eee',
borderColor: 'black',
}),
testContainer4: RX.Styles.createViewStyle({
flex: 1,
height: 150,
margin: 20,
borderWidth: 1,
backgroundColor: '#eee',
borderColor: 'black',
}),
success: RX.Styles.createViewStyle({
borderWidth: 2,
backgroundColor: 'green'
Expand All @@ -59,6 +67,10 @@ interface TouchViewState {
view3TouchResponderTestStart: boolean;
view3TouchResponderTestGrant: boolean;
view3TouchResponderTestRelease: boolean;
touchPositionOnPage: {
x: number | null
y: number | null
};
nestedViewTouchTestParent: boolean;
nestedViewTouchTestChild: boolean;
pressEvent?: RX.Types.TouchEvent;
Expand All @@ -75,6 +87,10 @@ class ViewTouch extends RX.Component<RX.CommonProps, TouchViewState> {
view3TouchResponderTestStart: false,
view3TouchResponderTestGrant: false,
view3TouchResponderTestRelease: false,
touchPositionOnPage: {
x: null,
y: null
},
nestedViewTouchTestParent: false,
nestedViewTouchTestChild: false,
};
Expand All @@ -83,7 +99,7 @@ class ViewTouch extends RX.Component<RX.CommonProps, TouchViewState> {
private static getTouchEventText(touchEvent?: RX.Types.TouchEvent): string {
if (touchEvent) {
return 'altKey = ' + touchEvent.altKey +
' changedTouches.length = ' + touchEvent.changedTouches.length +
' changedTouches.length = ' + (touchEvent.changedTouches && touchEvent.changedTouches.length) +
' ctrlKey = ' + touchEvent.ctrlKey +
' metaKey = ' + touchEvent.metaKey +
' shiftKey = ' + touchEvent.shiftKey +
Expand Down Expand Up @@ -171,6 +187,27 @@ class ViewTouch extends RX.Component<RX.CommonProps, TouchViewState> {
}}
/>
</RX.View>
<RX.View style={ _styles.explainTextContainer }>
<RX.Text style={ _styles.explainText }>
{ 'When touching this view, it will display the page coordinates of the touch position.' }
</RX.Text>
</RX.View>
<RX.View
style={ _styles.testContainer4 }
onResponderMove={ e => {
const touch = e.touches[0];
if (touch) {
this.setState({ touchPositionOnPage: {
x: Math.round(touch.pageX),
y: Math.round(touch.pageY)
}});
}
}}
>
<RX.Text style={ _styles.labelText }>
{ `Touch position on page: x: ${this.state.touchPositionOnPage.x} y: ${this.state.touchPositionOnPage.y}`}
</RX.Text>
</RX.View>
</RX.View>
);
}
Expand Down
2 changes: 2 additions & 0 deletions src/web/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ export class View extends ViewBase<RX.Types.ViewProps, RX.Types.Stateless, RX.Vi
onMouseLeave: this.props.onMouseLeave,
onMouseOver: this.props.onMouseOver,
onMouseMove: this.props.onMouseMove,
// Weird things happens: ReactXP.Types.Touch is not assignable to React.Touch
onTouchMove: this.props.onResponderMove as React.HTMLAttributes<any>['onTouchMove'],
draggable: this.props.onDragStart ? true : undefined,
onDragStart: this.props.onDragStart,
onDrag: this.props.onDrag,
Expand Down