bdf99468e7
为推荐页滑动提交后的 rail 复位增加无过渡 resetting 状态 补充推荐滑动状态模型测试覆盖 resetting 类名 补齐推荐页交互测试中的小程序运行态 mock
81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import type { PlatformPublicGalleryCard } from './rpgEntryWorldPresentation';
|
|
|
|
export const RECOMMEND_ENTRY_SWIPE_THRESHOLD_PX = 36;
|
|
export const RECOMMEND_ENTRY_COMMIT_ANIMATION_MS = 180;
|
|
export const RECOMMEND_ENTRY_DRAG_LIMIT_PX = 160;
|
|
|
|
export type RecommendSwipeDirection = 1 | -1;
|
|
|
|
export type RecommendSwipeRailState = {
|
|
offsetY: number;
|
|
commitDirection: RecommendSwipeDirection | null;
|
|
isResetting?: boolean;
|
|
};
|
|
|
|
/** 收口推荐卡纵向滑动的纯判定,页面只保留 pointer 与动画副作用。 */
|
|
export function hasRecommendDragStarted(deltaY: number) {
|
|
return Math.abs(deltaY) >= RECOMMEND_ENTRY_SWIPE_THRESHOLD_PX / 2;
|
|
}
|
|
|
|
export function clampRecommendDragOffset(
|
|
deltaY: number,
|
|
stageHeight: number,
|
|
) {
|
|
const dragLimit =
|
|
stageHeight > 0 ? stageHeight : RECOMMEND_ENTRY_DRAG_LIMIT_PX;
|
|
return Math.max(-dragLimit, Math.min(dragLimit, deltaY));
|
|
}
|
|
|
|
export function resolveRecommendDragCommitDirection(
|
|
deltaY: number,
|
|
): RecommendSwipeDirection | null {
|
|
if (Math.abs(deltaY) < RECOMMEND_ENTRY_SWIPE_THRESHOLD_PX) {
|
|
return null;
|
|
}
|
|
|
|
return deltaY < 0 ? 1 : -1;
|
|
}
|
|
|
|
export function resolveRecommendCommitOffset(
|
|
direction: RecommendSwipeDirection,
|
|
stageHeight: number,
|
|
viewportHeight: number,
|
|
) {
|
|
const commitDistance = stageHeight > 0 ? stageHeight : viewportHeight;
|
|
return direction === 1 ? -commitDistance : commitDistance;
|
|
}
|
|
|
|
export function buildRecommendSwipeRailClassName(
|
|
state: RecommendSwipeRailState,
|
|
) {
|
|
if (state.isResetting) {
|
|
return 'platform-recommend-swipe-rail--resetting';
|
|
}
|
|
|
|
if (state.commitDirection) {
|
|
return 'platform-recommend-swipe-rail--committing';
|
|
}
|
|
|
|
return state.offsetY === 0
|
|
? 'platform-recommend-swipe-rail--settled'
|
|
: 'platform-recommend-swipe-rail--dragging';
|
|
}
|
|
|
|
export function shouldAnimateRecommendSwipe(params: {
|
|
isAuthenticated: boolean;
|
|
hasActiveEntry: boolean;
|
|
entryCount: number;
|
|
}) {
|
|
return (
|
|
params.isAuthenticated && params.hasActiveEntry && params.entryCount > 1
|
|
);
|
|
}
|
|
|
|
export function buildRecommendShareText(params: {
|
|
entry: PlatformPublicGalleryCard;
|
|
publicWorkCode: string;
|
|
detailUrl: string;
|
|
}) {
|
|
return `邀请你来玩《${params.entry.worldName}》\n作品号:${params.publicWorkCode}\n${params.detailUrl}`;
|
|
}
|