eturn (
{item}
allItems.splice(index, 1);
this.setState({ allItems });
}} />
);
});
return (
style={styles.input}
placeholder=”Add item”
value={inputText}
onChangeText={text => this.setState({ inputText: text })}
/>
{items}
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
backgroundColor: ‘#F5FCFF’,
},
input: {
width: ‘80%’,
borderWidth: 1,
borderColor: ‘#000000’,
margin: 10,
padding: 10
},
list: {
flex: 1,
width: ‘80%’,
padding: 10
},
listItem: {
flexDirection: ‘row’,
justifyContent: ‘space-between’,
alignItems: ‘center’,
borderWidth: 1,
borderColor: ‘#000000’,
padding: 10
}
});
“`
這是一個(gè)簡(jiǎn)單的應(yīng)用程序,用于添加和刪除項(xiàng)目。當(dāng)用戶點(diǎn)擊“添加”按鈕時(shí),應(yīng)用程序?qū)⑽谋究蛑械奈谋咎砑拥剿许?xiàng)目數(shù)組中。然后,應(yīng)用程序?qū)⒅匦落秩卷?xiàng)目列表。每個(gè)項(xiàng)目都顯示了在列表項(xiàng)中,其中包含一個(gè)刪除按鈕。當(dāng)用戶點(diǎn)擊刪除按鈕時(shí),項(xiàng)目將從數(shù)組中刪除,并將更智電瑞創(chuàng)新后的項(xiàng)目列表再次呈現(xiàn)。
這是React Native構(gòu)建移動(dòng)應(yīng)用程序的主要過程。通過使用React Native,我們可以使用JavaScript編寫應(yīng)用程序,并將代碼重用于iOS和Android平臺(tái)。此外,React Native還提供了許多組件和功能,可用于構(gòu)建漂亮的和高效的應(yīng)用程序。