selectable 设置不生效

来源:7-3 Text 使用占比最高的组件,使用简单,深入复杂

西瓜一号

2024-06-21

对照的写的
代码没错,就是这个设置不生效
长按,双击都试了,没反应

点击事件,长按事件也不触发
是不是安卓模拟器要设置什么?默认是不能操作模拟器

学完text组件,上面没反应的又都可以了

import React from "react";
import { StyleSheet, Text, View } from "react-native";

export default () => {

    return (
        <View style={s.root}>
            <Text
                style={s.txt}

                //默认是0
                numberOfLines={1}

                //clip 多余的剪掉
                // tail 尾部省略  默认值
                // head 头部省略
                // middle 中间省略
                ellipsizeMode='tail'

                // 是否可选中 默认false
                selectable={true}
                // 选中后背景颜色
                selectionColor='red'

                onPress={() => {
                    console.log(`onPress,,,,,,`)
                }}

                onLongPress={() => {
                    console.log(`onLongPress,,,,,,`)
                }}

                //是否跟随系统字号 默认是true
                allowFontScaling={false}

            >
                123456789
                {/* <Text style={s.innerText}>sadhjk</Text> */}
            </Text>
        </View>
    );
}


const s = StyleSheet.create({
    root: {
        width: '100%',
        height: '100%',
        backgroundColor: '#f0f0f0',
    },

    txt: {
        fontSize: 34,
        fontWeight: 'bold',
        fontFamily: '',
        backgroundColor: '#c0c0c0',
        height: 200,
        textAlign: 'center',
        textAlignVertical: 'center', //垂直方向居中

        //需要一起使用
        textDecorationStyle: 'solid',  // solid:线  搭配使用
        textDecorationLine: 'underline', //underline:下划线   line-through:删除线

        //需要一起使用
        textShadowColor: 'red',
        textShadowRadius: 10,
        textShadowOffset: { width: 4, height: 4 }


    },
    // 嵌套文字 字号,颜色 不写就会沿用外面的样式,不能写pandding,margin
    innerText: {
        fontSize: 64,
        color: 'red',
        fontWeight: 'bold',
    },
});
写回答

2回答

FE大公爵

2024-06-27

https://img1.sycdn.imooc.com/szimg/667cff500827db2005620418.jpg

我在本地测试了你的代码,是OK的。点击和长按都是可以的
0
0

FE大公爵

2024-06-23

现在具体的问题是什么。如果代码不长,可以贴到评论区,如果代码多就发到QQ群吧
0
3
西瓜一号
回复
FE大公爵
回复 FE大公爵:我后面又测试了,好像是模拟器的原因,我重新npm run android又可以了,有些是reload模拟器就正常了
2024-06-27
共3条回复

RN从0到1系统精讲与小红书APP实战

30+小案例+2个实战项目,快人一步提升个职业竞争力

295 学习 · 211 问题

查看课程