reactjs - TextInput 元素顶部的按钮不起作用
问题描述
我正在尝试在多行文本输入之上制作可见的按钮列表,该列表现在正在工作。但是,当我单击其中一个按钮时,什么也没有发生。
我正在使用 zIndex 将 childComponent 置于 TextInput 之上,现在当我单击这些按钮时,TextInput 获得焦点而不是触发按钮单击事件。
我刚开始学习 react-native,所以我无法理解我需要在哪里进行更改以使其正常工作。
示例代码结构如下:*
const Component_1=()=>{
const UpdateTextInput=(ip,callType)=>{
console.log(ip);
}
return (<View keyboardShouldPersistTaps={'handle'}>
<View style={{flexDirection:'row',backgroundColor:'#fff',zIndex:10}}>
<ChildComponent callBackFunc={(ip,callType)=>UpdateTextInput(ip,callType)} />
</View>
<View>
<TextInput
multiline
onChangeText={(text)=>updateString(text,'')}
/>
</View>
</View>
)
}
export default Component_1;
const ChildComponent=({callBackFunc})=>{
const [ButtonSection,SetButtonSection]=useState(false)
return (
<View style={{flexDirection:'row-reverse'}}>
<View style={{flexDirection:'column',width:'15%',position:'absolute'}} >
<TouchableOpacity onPress={()=>SetButtonSection(!ButtonSection)} style={{borderColor:'tomato',borderEndWidth:1}}>
<Icon
name='arrow-drop-down'
size={25}
type='material'
iconStyle={{color:'tomato',textAlign:'center',paddingHorizontal:20,paddingVertical:8,fontSize:20}}
/>
</TouchableOpacity>
{ButtonSection==true
?<View style={{flexDirection:'column',position:'relative',backgroundColor:'#ccc'}}>
<TouchableOpacity onPress={()=>callBackFunc('','CLR')} style={{borderColor:'tomato',borderEndWidth:1}}>
<Icon
name='block'
size={25}
type='material'
iconStyle={{color:'tomato',textAlign:'center',paddingHorizontal:10,paddingVertical:8,fontSize:20}}
/>
</TouchableOpacity>
<TouchableOpacity onPress={()=>callBackFunc('','COPY')} style={{borderColor:'tomato',borderEndWidth:1}}>
<Icon
name='content-copy'
size={25}
type='material'
iconStyle={{color:'tomato',textAlign:'center',paddingHorizontal:10,paddingVertical:8,fontSize:20}}
/>
</TouchableOpacity>
<TouchableOpacity onPress={()=>callBackFunc('','SAVE')} style={{borderColor:'tomato',borderEndWidth:1}}>
<Icon
name='save'
size={25}
type='material'
iconStyle={{color:'tomato',textAlign:'center',paddingHorizontal:10,paddingVertical:8,fontSize:20}}
/>
</TouchableOpacity>
<Button title='BTN' onPress={()=>console.log('Button1')
}/>
</View>
:null
}
</View>
<ScrollView horizontal={true} showsHorizontalScrollIndicator={false} keyboardShouldPersistTaps={'handle'} style={{marginRight:50}}>
<Item/>
</ScrollView>
</View>
)
}
export default ChildComponent
解决方案
不要使用 zIndex,而是使用视图中的绝对位置。
position: 'absolute'
为子组件的视图赋予绝对位置
推荐阅读
- rxandroidble - RXAndroidBLE 无法扫描设备和读取特征
- javascript - 如何使用带有续集的节点中的关系的软删除
- django - 系统管理员的 REST api
- c++ - 错误:预期的主要 - 浮点之前的表达式
- python - 如何在我的应用程序中包含 python IDE
- prolog - Prolog 剪切和失败未按预期工作
- javascript - 使用 Express 和 mongoDB 为用户提供高级访问权限并为其设置过期时间
- html - 为什么当我将鼠标悬停在这个具有 3d 旋转效果的元素上时,它会意外拉伸?
- django - 如何获取与产品类别页面上显示的产品关联的所有产品属性的列表?
- javascript - 角文本旋转器