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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744106219a4558737.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信