Skip to content
Permalink
Browse files

fix(event): touchmove event prevent default

  • Loading branch information...
yyc-git committed May 11, 2019
1 parent 9e0bf23 commit ee51005320b5f5bacb60d3aa1377f3c537eb45e5
@@ -7,6 +7,19 @@ let _getBody = () => DomExtend.document##body |> bodyToEventTarget;
let _fromPointDomEvent = (eventName, state) =>
WonderBsMost.Most.fromEvent(eventName, _getBody(), false);

let _fromTouchMoveDomEventAndPreventnDefault = state =>
Obj.magic(
WonderBsMost.Most.fromEvent,
"touchmove",
_getBody(),
{"passive": false},
)
|> WonderBsMost.Most.tap(event =>
HandlePointDomEventMainService.preventDefault(
event |> eventTargetToTouchDomEvent |> touchDomEventToPointDomEvent,
)
);

let _fromKeyboardDomEvent = (eventName, state) =>
WonderBsMost.Most.fromEvent(eventName, _getBody(), false);

@@ -378,9 +391,9 @@ let _fromPCDomEventArr = state => [|
_fromPointDomEvent("mouseup", state)
|> WonderBsMost.Most.tap(event => _execMouseEventHandle(MouseUp, event)),
_fromPointDomEvent("mousemove", state)
|> WonderBsMost.Most.tap(event => {
_execMouseMoveEventHandle(MouseMove, event);
}),
|> WonderBsMost.Most.tap(event =>
_execMouseMoveEventHandle(MouseMove, event)
),
_fromPointDomEvent("mousewheel", state)
|> WonderBsMost.Most.tap(event => _execMouseEventHandle(MouseWheel, event)),
_fromPointDomEvent("mousedown", state)
@@ -413,14 +426,14 @@ let _fromMobileDomEventArr = state => [|
|> WonderBsMost.Most.tap(event => _execTouchEventHandle(TouchEnd, event)),
_fromPointDomEvent("touchstart", state)
|> WonderBsMost.Most.tap(event => _execTouchEventHandle(TouchStart, event)),
_fromPointDomEvent("touchmove", state)
_fromTouchMoveDomEventAndPreventnDefault(state)
|> WonderBsMost.Most.tap(event =>
_execTouchMoveEventHandle(TouchMove, event)
),
_fromPointDomEvent("touchstart", state)
|> WonderBsMost.Most.tap(event => _execTouchDragStartEventHandle(event))
|> WonderBsMost.Most.flatMap(event =>
_fromPointDomEvent("touchmove", state)
_fromTouchMoveDomEventAndPreventnDefault(state)
|> WonderBsMost.Most.until(
_fromPointDomEvent("touchend", state)
|> WonderBsMost.Most.tap(event =>
@@ -1492,6 +1492,43 @@ let _ =
describe("bind touchmove event", () => {
_testTouchEvent(TouchMove, "touchmove");

test("preventDefault", () => {
let state = TouchEventTool.prepare(~sandbox, ());
let state = state |> NoWorkerJobTool.execInitJobs;
let preventDefaultFunc = createEmptyStubWithJsObjSandbox(sandbox);
let stopPropagationFunc =
createEmptyStubWithJsObjSandbox(sandbox);

let state =
ManageEventAPI.onTouchEvent(
TouchMove,
0,
(. event: touchEvent, state) => state,
state,
);

let state = MainStateTool.setState(state);
EventTool.triggerDomEvent(
"touchmove",
EventTool.getPointEventBindedDom(state),
TouchEventTool.buildTouchEvent(
~changedTouches=[|
TouchEventTool.buildTouchData(~pageX=10, ~pageY=20, ()),
|],
~preventDefaultFunc,
~stopPropagationFunc,
(),
),
);
let state = EventTool.restore(state);

(
preventDefaultFunc |> getCallCount,
stopPropagationFunc |> getCallCount,
)
|> expect == (1, 1);
});

describe("test touch event", () =>
describe("test movementDelta", () =>
test("set lastX, lastY after handle", () => {
@@ -11,8 +11,8 @@ let setIsDrag = HandleTouchEventMainService.setIsDrag;
let buildTouchData = (~pageX=10, ~pageY=20, ()) => {
"clientX": 0,
"clientY": 0,
"pageX",
"pageY",
"pageX": pageX,
"pageY": pageY,
"identifier": 0,
"screenX": 0,
"screenY": 0,
@@ -27,14 +27,17 @@ let buildTouchEvent =
~touches=[|buildTouchData()|],
~changedTouches=[|buildTouchData()|],
~targetTouches=[|buildTouchData()|],
~preventDefaultFunc=() => (),
~stopPropagationFunc=() => (),
(),
) => {
"touches": touches,
"changedTouches": changedTouches,
"targetTouches": targetTouches,
"preventDefault": preventDefaultFunc,
"stopPropagation": stopPropagationFunc,
};


let prepareWithState =
(
~sandbox,
@@ -57,8 +60,6 @@ let prepareWithState =
MainStateTool.unsafeGetState();
};



let prepare =
(
~sandbox,

0 comments on commit ee51005

Please sign in to comment.
You can’t perform that action at this time.