【问题标题】:JSX not visible in react native android mobile but visible in emulatorJSX 在 react native android mobile 中不可见,但在模拟器中可见
【发布时间】:2021-02-15 21:59:24
【问题描述】:

我有一个奇怪的错误,在模拟器中可以看到定价并且工作正常,但是在移动设备上检查时,它没有显示,虽然它在那里但只是没有显示。我尝试过更改字体颜色、添加 if 条件等,但都不起作用。

另外,在注意到并解决这个错误时,我发现当数字在小数点后很大时,它确实会显示出来。(屏幕截图)但当它更小时不会显示。

Emulator Screenshot

Mobile Screenshot price visible

Mobile Screenshot price not visible

用于在价格中添加逗号的函数。

export function numberWithCommas(x) {
    var parts = x.toString().split(".");
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
    return parts.join(".");
}

用于在末尾预览总计的代码。

return (
        <View style={{ flex: 1 }}>
            <Tab.Navigator>

                <Tab.Screen name="One-Time Cart" component={OneTimeCart} />
                <Tab.Screen name="Subscription Cart" component={SubscriptionCart} />

            </Tab.Navigator>

            <View style={styles.cartTotal}>
                <View style={styles.cartTotalSubView}>
                    <Text style={styles.cartAllText}>One Time Cart:</Text>
                    <Text style={[styles.price, styles.cartAllText]}>₹ {numberWithCommas(grandTotal[0])}</Text>
                </View>
                <View style={styles.cartTotalSubView}>
                    <Text style={styles.cartAllText}>SubScription Cart:</Text>
                    <Text style={[styles.price, styles.cartAllText]}>₹ {numberWithCommas(grandTotal[1])}</Text>
                </View>
                <View style={styles.cartTotalSubView}>
                    <Text style={styles.cartAllText}>Total:</Text>
                    <Text style={[styles.price, styles.cartAllText]}>₹ {numberWithCommas(grandTotal[0] + grandTotal[1])}</Text>
                </View>
            </View>

            <View>
                <Button style={styles.checkoutButton} onPress={() => navigation.navigate("Checkout")}><Text style={styles.buttonText}>CHECKOUT</Text></Button>
            </View>
        </View>

    )

【问题讨论】:

    标签: react-native react-redux jsx custom-font


    【解决方案1】:

    找到了导致此问题的原因的一些答案。问题在于 ₹ 符号,如果我将其删除。它出现了。将不断更新如何使其与符号一起使用

    Edit1:所以作为字符串的 JSX 不会以某种方式实时更新,因为我使用 redux 值将其转换为逗号类型价格,然后用空格单独添加卢比符号。删除它可以实时呈现并且没有问题。不知何故,转换为字符串的 redux 状态值不起作用。

    【讨论】:

      猜你喜欢
      • 2015-02-21
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      • 2018-09-22
      • 2017-09-21
      • 2014-01-15
      • 1970-01-01
      • 2021-02-19
      相关资源
      最近更新 更多