Skip to content

Commit

Permalink
fix: scrolling on mobile is cancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
bbohlender committed Jun 25, 2024
1 parent c6f2e3f commit 8ecf36f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 40 deletions.
16 changes: 9 additions & 7 deletions packages/uikit/src/components/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,19 @@ export function createContainer(
parentContext.root.panelGroupManager,
initializers,
)
const interactionPanel = createInteractionPanel(
orderInfo,
parentContext.root,
parentContext.clippingRect,
flexState.size,
initializers,
)
const scrollHandlers = computedScrollHandlers(
scrollPosition,
parentContext.anyAncestorScrollable,
flexState,
object,
interactionPanel,
properties,
parentContext.root,
initializers,
Expand All @@ -158,13 +166,7 @@ export function createContainer(
orderInfo,
root: parentContext.root,
scrollPosition,
interactionPanel: createInteractionPanel(
orderInfo,
parentContext.root,
parentContext.clippingRect,
flexState.size,
initializers,
),
interactionPanel,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers),
initializers,
})
Expand Down
22 changes: 12 additions & 10 deletions packages/uikit/src/components/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,22 @@ export function createImage(
parentContext.root.panelGroupManager,
initializers,
)
const interactionPanel = createImageMesh(
mergedProperties,
texture,
parentContext,
flexState,
orderInfo,
parentContext.root,
isVisible,
initializers,
)
const scrollHandlers = computedScrollHandlers(
scrollPosition,
parentContext.anyAncestorScrollable,
flexState,
object,
interactionPanel,
properties,
parentContext.root,
initializers,
Expand All @@ -187,16 +198,7 @@ export function createImage(
anyAncestorScrollable: computedAnyAncestorScrollable(flexState.scrollable, parentContext.anyAncestorScrollable),
initializers,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers),
interactionPanel: createImageMesh(
mergedProperties,
texture,
parentContext,
flexState,
orderInfo,
parentContext.root,
isVisible,
initializers,
),
interactionPanel,
clippingRect: computedClippingRect(
globalMatrix,
flexState,
Expand Down
24 changes: 13 additions & 11 deletions packages/uikit/src/components/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,6 @@ export function createRoot(
initializers,
)

const scrollHandlers = computedScrollHandlers(
scrollPosition,
undefined,
flexState,
object,
properties,
ctx,
initializers,
)

setupLayoutListeners(style, properties, flexState.size, initializers)

const gylphGroupManager = new GlyphGroupManager(renderOrder, depthTest, pixelSize, ctx, object, initializers)
Expand All @@ -214,6 +204,18 @@ export function createRoot(
size: flexState.size,
})

const interactionPanel = createInteractionPanel(orderInfo, rootCtx, undefined, flexState.size, initializers)
const scrollHandlers = computedScrollHandlers(
scrollPosition,
undefined,
flexState,
object,
interactionPanel,
properties,
ctx,
initializers,
)

return Object.assign(flexState, {
scrollPosition,
mergedProperties,
Expand All @@ -223,7 +225,7 @@ export function createRoot(
node,
orderInfo,
initializers,
interactionPanel: createInteractionPanel(orderInfo, rootCtx, undefined, flexState.size, initializers),
interactionPanel,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers),
root: rootCtx,
})
Expand Down
18 changes: 11 additions & 7 deletions packages/uikit/src/components/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,21 @@ export function createSvg(
parentContext.root.panelGroupManager,
initializers,
)

const interactionPanel = createInteractionPanel(
orderInfo,
parentContext.root,
parentContext.clippingRect,
flexState.size,
initializers,
)

const scrollHandlers = computedScrollHandlers(
scrollPosition,
parentContext.anyAncestorScrollable,
flexState,
object,
interactionPanel,
properties,
parentContext.root,
initializers,
Expand All @@ -199,13 +209,7 @@ export function createSvg(
initializers,
centerGroup,
handlers: computedHandlers(style, properties, defaultProperties, hoveredSignal, activeSignal, scrollHandlers),
interactionPanel: createInteractionPanel(
orderInfo,
parentContext.root,
parentContext.clippingRect,
flexState.size,
initializers,
),
interactionPanel,
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/uikit/src/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Intersection } from 'three'
import { Intersection, Object3D } from 'three'

export type ThreeEvent<TSourceEvent> = Intersection & {
nativeEvent: TSourceEvent
Expand Down
14 changes: 10 additions & 4 deletions packages/uikit/src/scroll.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReadonlySignal, Signal, computed, effect, signal } from '@preact/signals-core'
import { Matrix4, Object3D, Vector2, Vector2Tuple, Vector3, Vector4Tuple } from 'three'
import { FlexNode, FlexNodeState, Inset } from './flex/node.js'
import { ColorRepresentation, Initializers, Subscriptions, computedBorderInset } from './utils.js'
import { Matrix4, Mesh, Vector2, Vector2Tuple, Vector3, Vector4Tuple } from 'three'
import { FlexNodeState, Inset } from './flex/node.js'
import { ColorRepresentation, Initializers, computedBorderInset } from './utils.js'
import { ClippingRect } from './clipping.js'
import { clamp } from 'three/src/math/MathUtils.js'
import { PanelProperties, createInstancedPanel } from './panel/instanced-panel.js'
Expand Down Expand Up @@ -74,6 +74,7 @@ export function computedScrollHandlers(
anyAncestorScrollable: Signal<readonly [boolean, boolean]> | undefined,
{ scrollable, maxScrollPosition }: FlexNodeState,
object: Object3DRef,
interactionPanel: Mesh,
listeners: Signal<ScrollListeners | undefined>,
root: Pick<RootContext, 'onFrameSet' | 'requestRender' | 'pixelSize' | 'requestFrame'>,
initializers: Initializers,
Expand Down Expand Up @@ -199,7 +200,12 @@ export function computedScrollHandlers(
object.current!.worldToLocal(interaction.point.copy(point))
},
onPointerUp: onPointerFinish,
onPointerLeave: onPointerFinish,
onPointerOut: (e: ThreeEvent<PointerEvent>) => {
if (e.object != interactionPanel) {
return
}
onPointerFinish(e)
},
onPointerCancel: onPointerFinish,
onPointerMove: (event) => {
const prevInteraction = downPointerMap.get(event.nativeEvent.pointerId)
Expand Down

0 comments on commit 8ecf36f

Please sign in to comment.