【问题标题】:After migrating to v5 image resize not working迁移到 v5 后图像大小调整不起作用
【发布时间】:2020-03-21 08:08:00
【问题描述】:

当前行为

在 react navigation v4 中,我使用了这段代码并且工作得很好。它确实调整了我的徽标图像 (300x80) 以完全适合并缩放到我的 80 像素标题中。

现在迁移到 v5 后,它不再扩展。就像“resizeMode”停止工作一样。

const navigationOptions = { headerTitle: <Image style={{height: 45}} resizeMode="contain" source={require('../assets/images/encabezado-1.png')}/>, headerStyle: { backgroundColor: 'white', shadowColor: 'none', }, headerTitleAlign: 'center', headerTitleStyle: { fontWeight: 'normal', fontFamily: 'Montserrat-SemiBold', }, }

预期行为

我希望我的图像能够被正确地包含和缩放。就像在 v4 中一样:

如何重现

将图像添加到 headerTitle 并尝试 resizeMode。

您的环境

  • 安卓 9
    • @react-navigation/native 5.2.2
    • @react-navigation/stack 5.2.3
    • react-native-gesture-handler 1.6.1
    • react-native-safe-area-context 0.7.3
    • react-native-screens 2.4.0
    • react-native 0.61.5
    • 节点 12.6.1

【问题讨论】:

    标签: react-native react-navigation react-navigation-stack react-navigation-v5 react-native-image


    【解决方案1】:

    resizeMode 仍在工作。您可以在 Stack.Screen -> options -> title 属性中使用。

    代码示例:

    <TakeSendStack.Navigator initialRouteName={"TakeSend"}>
          <TakeSendStack.Screen name="TakeSend" options={{ title: <Image style={{height: 45}} source={require('../assets/logo/logo.png')}/> }} component={TakeSend} />
    </TakeSendStack.Navigator>
    

    添加调整大小模式

    <TakeSendStack.Navigator initialRouteName={"TakeSend"}>
          <TakeSendStack.Screen name="TakeSend" options={{ title: <Image style={{height: 45}} resizeMode="contain" source={require('../assets/logo/logo.png')}/> }} component={TakeSend} />
    </TakeSendStack.Navigator>
    

    【讨论】:

    • 我尝试了你所做的但没有结果:}}/> 我一直有同样的行为。
    • Android 问题。您可以在 Stack.Navigator 中添加 headerTitleAlign 并在 Image 项中添加自定义宽度吗? }}/> ...
    猜你喜欢
    • 1970-01-01
    • 2014-05-13
    • 2014-08-29
    • 2014-05-12
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 2018-06-24
    • 2014-04-28
    相关资源
    最近更新 更多