最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how to get @react-navigationstack current stack depth prgress - Stack Overflow

programmeradmin7浏览0评论

Is there any way to know the progress of the current depth?

For example, If we go from 0 to 1, 0.1, 0.2, 0.3, ..., 1

If we go from 1 to 2, 1.1, 1.2, 1.3, ..., 2

If we go from 2 to 1 again, 1.9, 1.8, 1.7, ..., 1

Is there any way to get this?

-under is my current codes-

import React from "react"
import { SharedValue } from "react-native-reanimated"
import { CardStyleInterpolators, StackCardInterpolationProps } from '@react-navigation/stack';
import { createContextHook } from "../provider/provider"
import { _DEFAULT_SCREEN_OPTION } from "../util/stack";

interface ProgressContextProps {
    progress: SharedValue<number>
}

const ProgressContext = React.createContext<ProgressContextProps|undefined>(undefined)

export const useProgress = () => createContextHook(ProgressContext, 'ProgressContext')

export const createCardStyleProgressInterpolator = ({ progress }: ProgressContextProps) => {
    return ({ 
        current,
        next,
        layouts,
        closing,
        index,
        swiping,
        inverted,
        insets
    }: StackCardInterpolationProps) => {
        const cp = current.progress;
        cp.addListener(({ value }) => {
            'worklet';
            if (value === 1) {
                if (progress.value == 0 /* || progressValue.value >= 0.99 */) {
                    progress.value = index > 0 ? 1 : 0
                }
            } else {
                progress.value = value;
            }
        });

        return CardStyleInterpolators.forHorizontalIOS({
            current,
            next,
            layouts,
            closing,
            index,
            swiping,
            inverted,
            insets
        });
    };
};

    
export default ProgressContext
发布评论

评论列表(0)

  1. 暂无评论