javascript - 反应原生位置相对而不移动其他内容
问题描述
我正在创建一个单击按钮时出现的自定义模式,类似于工具提示外观,但具有可选字段。
我遇到的问题是模态正在将其下方的内容向下推(不碍事),我只是希望它超越一切。
我已经使用片段来尝试将模式保持在与所有其他元素相同的级别和相对位置以保持单击位置的位置。
这是按钮的结构和它下面的模态。
<>
<View style={[styles.f_con]}>
<Text style={[styles.f_title, item.required && styles.f_required]}>{item.title}</Text>
<TouchableOpacity style={styles.d_btn} onPress={e => setVisible(true)}>
<Text>{selection !== null ? item.options[selection] : 'Select from list'}</Text>
</TouchableOpacity>
</View>
<SelectModal visible={visible} close={close} item={item} clear={() => makeSelection(null)}>
{item.options.map((option, index) => (
<TouchableOpacity style={styles.s_option_con} key={index} onPress={() => makeSelection(index)} value={option}>
<Text style={styles.s_option_txt}>{option}</Text>
</TouchableOpacity>
))}
</SelectModal>
</>
这是我的模态样式
modal: {
position: 'relative',
backgroundColor: Colors.secondaryBackground,
top: -30,
left: 100,
height: 'auto',
borderRadius: 12,
width: 250,
zIndex: 20
}
解决方案
如果有人遇到类似问题,我找到了解决方案:
我用模态重组了项目,将模态作为子项,如下所示:
<View style={[styles.f_con, { zIndex: 2 }]}>
<Text style={[styles.f_title, item.required && styles.f_required]}>{item.title}</Text>
<TouchableOpacity style={styles.d_btn} onPress={e => setVisible(true)}>
<Text>{selection !== null ? item.options[selection] : 'Select from list'}</Text>
</TouchableOpacity>
<SelectModal visible={visible} close={close} item={item} clear={() => makeSelection(null)}>
{item.options.map((option, index) => (
<TouchableOpacity style={styles.s_option_con} key={index} onPress={() => makeSelection(index)} value={option}>
<Text style={styles.s_option_txt}>{option}</Text>
</TouchableOpacity>
))}
</SelectModal>
</View>
我将模式的位置更改为position: 'absolute'
并确保项目的 zIndex 是 zIndex: 2
并且所有工作。
片段是不必要的。
推荐阅读
- python - 双重装饰器,为什么我的封闭函数之一没有执行?
- react-native - 无法在反应式中解析模块加密
- javascript - Ionic3 标签(如点击功能)在 InnerHTML 中不起作用
- jquery - JSP Error Unable to locate tag attribute info for tag attribute aria- describeby spring form
- asp.net-mvc - 在控制器 [ASP.Net MVC] 中动态检查验证
- php - 使用php替换多种格式的电话前缀
- php - 如何从 Laravel 5.5 中的 DB Json 值比较和获取数据
- javascript - 将图像上传到firebase没有错误,但图像没有出现在存储中
- c++ - 移动后是否需要重置 std::list ?
- vba - 无法处理不同工作表上的命令