为了账号安全,请及时绑定邮箱和手机立即绑定

cardStyleInterpolator 道具的类型

cardStyleInterpolator 道具的类型

慕运维8079593 2023-03-03 10:06:11
我在我的导航堆栈中使用它:  <NavigationStack.Screen                    name="UserMenu"                    component={UserMenu}                    options={{                      headerShown: false,                      cardStyleInterpolator: forSlideFromLeft,                    }}                  />const forSlideFromLeft = (props) => {  const { current, layouts } = props;  console.log('PROPS FROM USER MENU', current)  console.log('PROPS FROM USER MENU2', layouts)  const translateX = current.progress.interpolate({    inputRange: [0, 1],    outputRange: [-layouts.screen.width, 0],  });  if (props.index === 2) {    return {      cardStyle: {        transform: [{ translateX }],      },    };  } else {    return {};  }};但我得到一个错误,props它Parameter 'props' implicitly has an 'any' type.可能是什么类型。如果我infer from usage在 VS Code 中,我会得到这个:(props: { index?: any; current?: any; layouts?: any; })但我不想使用any类型。如果我在控制台上打印current和值,我会得到如下信息:layout当前的:{progress: AnimatedInterpolation}progress: AnimatedInterpolation {_listeners: {…}, _children: Array(0), _parent: AnimatedValue, _config: {…}, _interpolation: ƒ, …}__proto__: Object布局:{screen: {…}}screen: {width: 411.4285583496094, height: 707.4285888671875}__proto__: Object我怎样才能解决这个问题?什么是适合在这里使用的类型?
查看完整描述

2 回答

?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

您可以StackCardInterpolationProps从导入类型react-navigation

https://github.com/react-navigation/react-navigation/blob/main/packages/stack/src/types.tsx


查看完整回答
反对 回复 2023-03-03
?
精慕HU

TA贡献1845条经验 获得超8个赞

在 React 导航 6 中

查看in的类型定义StackCardStyleInterpolator@react-navigation。这应该适用于 Stack 中的动画屏幕。

forSlideFromLeft您可以像这样实现您的方法:

import {

  StackCardInterpolationProps,

  StackCardInterpolatedStyle,

} from "@react-navigation/stack";


const forSlideFromLeft = (

 { current, layouts, index }: StackCardInterpolationProps

): StackCardInterpolatedStyle => {

  const translateX = current.progress.interpolate({

    inputRange: [0, 1],

    outputRange: [-layouts.screen.width, 0],

  });

  if (index === 2) {

    return {

      cardStyle: {

        transform: [{ translateX }],

      },

    };

  } else {

    return {};

  }

};

还有一个StackHeaderStyleInterpolator用于动画标题的。



查看完整回答
反对 回复 2023-03-03
  • 2 回答
  • 0 关注
  • 100 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号