mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-04 09:13:24 +00:00
FIX - preserve Home Screen drag across pages
This commit is contained in:
@@ -7,6 +7,8 @@ import {
|
||||
springboardEdgeDirection,
|
||||
springboardPageDragCompensation,
|
||||
springboardSwipeIntent,
|
||||
springboardViewportDeltaToLocal,
|
||||
springboardViewportToLocal,
|
||||
} from '@/utils/springboardDrag'
|
||||
|
||||
describe('springboard widget drag', () => {
|
||||
@@ -57,4 +59,16 @@ describe('springboard widget drag', () => {
|
||||
expect(springboardPageDragCompensation(2, 3, 368)).toBe(368)
|
||||
expect(springboardPageDragCompensation(2, 2, 368)).toBe(0)
|
||||
})
|
||||
|
||||
it('converts viewport coordinates into local phone coordinates under zoom', () => {
|
||||
expect(
|
||||
springboardViewportToLocal(169, 238, 100, 100, 253.92, 582.36, 368, 844),
|
||||
).toEqual({ x: 100, y: 200 })
|
||||
expect(
|
||||
springboardViewportToLocal(200, 250, 100, 50, 0, 0, 368, 844),
|
||||
).toEqual({ x: 100, y: 200 })
|
||||
expect(
|
||||
springboardViewportDeltaToLocal(69, 138, 253.92, 582.36, 368, 844),
|
||||
).toEqual({ x: 100, y: 200 })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,6 +11,42 @@ export type SpringboardHomeEdgeTurn = SpringboardEdgeTurn & {
|
||||
|
||||
export type SpringboardSwipeIntent = 'horizontal' | 'pending' | 'vertical'
|
||||
|
||||
export type SpringboardLocalPoint = {
|
||||
x: number
|
||||
y: number
|
||||
}
|
||||
|
||||
export function springboardViewportToLocal(
|
||||
clientX: number,
|
||||
clientY: number,
|
||||
viewportLeft: number,
|
||||
viewportTop: number,
|
||||
viewportWidth: number,
|
||||
viewportHeight: number,
|
||||
layoutWidth: number,
|
||||
layoutHeight: number,
|
||||
): SpringboardLocalPoint {
|
||||
const scaleX = viewportWidth > 0 ? layoutWidth / viewportWidth : 1
|
||||
const scaleY = viewportHeight > 0 ? layoutHeight / viewportHeight : 1
|
||||
return {
|
||||
x: (clientX - viewportLeft) * scaleX,
|
||||
y: (clientY - viewportTop) * scaleY,
|
||||
}
|
||||
}
|
||||
|
||||
export function springboardViewportDeltaToLocal(
|
||||
deltaX: number,
|
||||
deltaY: number,
|
||||
viewportWidth: number,
|
||||
viewportHeight: number,
|
||||
layoutWidth: number,
|
||||
layoutHeight: number,
|
||||
): SpringboardLocalPoint {
|
||||
const scaleX = viewportWidth > 0 ? layoutWidth / viewportWidth : 1
|
||||
const scaleY = viewportHeight > 0 ? layoutHeight / viewportHeight : 1
|
||||
return { x: deltaX * scaleX, y: deltaY * scaleY }
|
||||
}
|
||||
|
||||
export function springboardPageDragCompensation(
|
||||
startPage: number,
|
||||
currentPage: number,
|
||||
|
||||
Reference in New Issue
Block a user