【发布时间】:2018-01-16 07:27:27
【问题描述】:
我想在 react native 中制作一个包含动态列表视图 Listview but only one row contains a button 的屏幕。我正在使用本机基础库来制作屏幕的 UI,其中给出了各种 ListView 组件,但没有给出如何制作这种类型的列表视图。我进行了很多搜索,但找不到任何具有此类 Listview 的库。
如果有人能建议一种方法来设计这种类型的列表视图,那将是一个非常大的帮助。提前致谢!!
这是我的代码实现
export default class AddNewMember extends Component {
constructor(props) {
super(props)
this.state = {
registerButtonClicked: false
}
}
registerButtonClick = () => {
this.setState({
registerButtonClicked: true
})
}
_renderRow = () => {
var items = [
'Simon Mignolet',
'Nathaniel Clyne',
'Dejan Lovren',
'Mama Sakho',
'Emre Can'
]
for (i = 0; i < items.length; i++) {
if (items[i] === 'Simon Mignolet') {
return (
<ListItem style={{ flex: 1 }}>
<Text style={{ marginLeft: 25 }}>Vikas</Text>
</ListItem>
)
} else {
return (
<ListItem style={{ flex: 1 }}>
<Text style={{ marginLeft: 25 }}>{items[i]}</Text>
</ListItem>
)
}
}
}
CardHeader = () => {
var items = [
'Simon Mignolet',
'Nathaniel Clyne',
'Dejan Lovren',
'Mama Sakho',
'Emre Can'
]
if (this.state.registerButtonClicked) {
return (
<List
style={{ marginTop: 12, flex: 1 }}
dataArray={items}
renderRow={item => (
<ListItem>
<Text style={{ marginLeft: 25 }}>{item}</Text>
</ListItem>
)}
/>
)
} else {
return (
<Content>
/* <Card transparent>
<CardItem>
<View style={{ flexDirection: 'row', flex: 0 }}>
<Text style={styles.participant_name}>
Harish Venkatesh
</Text>
<TouchableOpacity
onPress={() => this.registerButtonClick()}
>
<Text
style={{
fontSize: 12,
marginLeft: 30,
letterSpacing: 0,
lineHeight: 16,
height: 20,
marginTop: 10,
width: 250
}}
>
Register New Player
</Text>
</TouchableOpacity>
</View>
</CardItem>
</Card>*/
<List
style={{ flex: 1, marginTop: 12 }}
dataArray={items}
renderRow={this._renderRow}
/>
</Content>
)
}
}
text = () => {
if (this.state.registerButtonClicked) {
return (
<Text
style={{
fontSize: 14,
color: '#951b1f',
letterSpacing: 0,
lineHeight: 20,
textAlign: 'left',
marginLeft: 30,
marginBottom: 12,
marginTop: 30
}}
>
Add New Participant
</Text>
)
} else {
return (
<Text
style={{
fontSize: 14,
color: '#000000',
letterSpacing: 0,
lineHeight: 20,
textAlign: 'left',
marginLeft: 30,
marginBottom: 12,
marginTop: 30
}}
>
PARTICIPANTS DETAILS{' '}
</Text>
)
}
}
registerCardorAddDetailsCard = () => {
if (this.state.registerButtonClicked) {
return (
<Card style={{ flex: 1, marginTop: 20 }} cardBody>
<Item
style={{
marginLeft: 27
}}
>
<Icon active name="person-add" />
<Input
style={{
fontSize: 17,
color: '#000000',
letterSpacing: 0
}}
placeholder="Participant Name"
/>
</Item>{' '}
<Item
style={{
marginLeft: 27
}}
>
<Icon active name="calendar" />
<Input
style={{
fontSize: 17,
color: '#000000',
letterSpacing: 0
}}
placeholder="Date of Birth"
keyboardType="numeric"
/>
</Item>{' '}
<Item
style={{
marginLeft: 27
}}
>
<Icon active name="calendar" />
<Input
style={{
fontSize: 17,
color: '#000000',
letterSpacing: 0
}}
placeholder="Email address"
keyboardType="email-address"
/>
</Item>
</Card>
)
} else {
return (
<Card cardBody>
{' '}
<Text
style={{
fontSize: 17,
marginLeft: 20,
marginTop: 15,
marginBottom: 15,
color: '#000000',
letterSpacing: 0,
opacity: 0.5
}}
>
+91-8840415633
</Text>
<Separator />
<Text
style={{
fontSize: 17,
color: '#000000',
letterSpacing: 0,
marginLeft: 27,
marginTop: 15,
marginBottom: 15,
opacity: 0.5
}}
>
30 Dec 1994
</Text>
<Separator />
<Item
style={{
marginLeft: 27
}}
>
<Input
style={{
fontSize: 17,
color: '#000000',
letterSpacing: 0
}}
placeholder="harishvenkatesh@ontroapp.com"
/>
</Item>
</Card>
)
}
}
render() {
return (
<View style={{ flex: 1 }}>
{this.CardHeader()} {this.text()}
{this.registerCardorAddDetailsCard()}
</View>
)
}
}
在 _renderRow 函数中,我正在尝试进行条件渲染,但仍然没有成功。
【问题讨论】:
-
您应该提供当前实现的代码
-
好的,我正在编辑我的帖子
-
我已经编辑了我的帖子,请看一下
标签: javascript reactjs listview react-native react-native-flatlist