javascript - 如何在本机反应中调整屏幕不同位置的单个组件?
问题描述
嗨!我是反应原生的新手。基本上,我有一个表单,其中三个字段正在使用月份选择器组件,该组件在点击打开时在该字段中固定的图标时打开取决于一个图标。
如果我单击第二个或第三个图标,则月份选择器位置将保持在第一个位置。
形式代码
<View style={styles.formWrapper} >
<View style={styles.titleField} >
<Text style={styles.titleFieldText} >Year Opened</Text>
</View>
<View style={styles.dobregisterFormWrapperText} >
<TextInput
placeholder="4/2/2021"
defaultValue={dob.toString()}
style={styles.dobregisterInputStyleText}
/>
<TouchableOpacity onPress={showDatePicker} >
<CalendarLogo style={styles.CalendarLogoColor} />
</TouchableOpacity>
</View>
<View style={styles.dobregisterFormWrapperText} >
<TextInput
placeholder="Card Limit"
style={styles.dobregisterInputStyleText}
onChangeText={cardLimit => setCardLimit(cardLimit)}
defaultValue={cardLimit}
keyboardType='numeric'
/>
</View>
<View style={styles.dobregisterFormWrapperText} >
<TextInput
placeholder="Current Balance"
style={styles.dobregisterInputStyleText}
onChangeText={cardBal => setCardBal(cardBal)}
defaultValue={cardBal}
keyboardType='numeric'
/>
</View>
</View>
<View style={styles.reportingForm} >
<View style={styles.titleField} >
<Text style={styles.titleFieldText} >Reporting Date</Text>
</View>
<View style={styles.dobregisterFormWrapperText} >
<TextInput
placeholder="4/2/2021"
defaultValue={dob.toString()}
style={styles.dobregisterInputStyleText}
/>
<TouchableOpacity onPress={showDatePicker} >
<CalendarLogo style={styles.CalendarLogoColor} />
</TouchableOpacity>
</View>
</View>
<View style={styles.reportingForm} >
<View style={styles.mainViewForSlots} >
<View style={styles.titleField} >
<Text style={styles.titleFieldText} >Available Slots</Text>
</View>
<TouchableOpacity style={styles.titleField} onPress={addField} >
<Text style={styles.titleFieldSlotText} >Add another Slots</Text>
</TouchableOpacity>
</View>
<View style={styles.dobregisterFormWrapperText} >
<TextInput
placeholder="4/2/2021"
defaultValue={dob.toString()}
style={styles.dobregisterInputStyleText}
/>
<TouchableOpacity onPress={showDatePicker} >
<CalendarLogo style={styles.CalendarLogoColor} />
</TouchableOpacity>
</View>
{ field }
</View>
**monthPicker显示代码**
{isDatePickerVisible === true ?
<View style={styles.calendarWrapper} >
<MyMonthPicker/>
</View>
:
null
}
月份选择器的 calendarWrapper 样式
calendarWrapper:{
width:wp('83%'),
marginLeft:wp('10%'),
borderRadius:10,
borderWidth:1,
borderColor:'grey',
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.29,
shadowRadius: 4.65,
elevation: 7,
position:'absolute',
top:hp('52%'), // adjustment
zIndex:99
},
现在在我的风格top:hp('52%')
中正在调整一个我需要显示月份选择器的位置,但是我如何动态设置它,以便如果我点击第一个图标,它会显示在该图标下方,如果我点击第二个图标,它会显示在该图标下方,同样适用第三?
解决方案
推荐阅读
- laravel - Laravel 节目编号
- kubernetes - 使用保险库中的领事模板读取机密
- telegram - 如何删除/销毁我的电报 api_id 和 api_hash
- node.js - 如何减少用于部署的 Docker 映像大小?
- javascript - ERR_EMPTY_RESPONSE(打开的每个地方)
- nativescript - 删除元素后列表视图未刷新
- java - 为什么在静态泛型方法的返回类型之前需要类型参数
- python - 如何用python绘制频率瀑布
- php - 在 google Talent Solutions api 上收到 400 错误请求错误 - symfony 4
- python-3.x - 找到要充电的机器人