React Native:键盘在第一次加载时关闭
React Native: Keyboard dismisses on first load
export default function HomeScreen() {
const [length, setLength] = useState("");
const [breadth, setBreadth] = useState("");
const [totalCost, setTotalCost] = useState("0");
const handleLengthChange = (text) => {
setLength(text);
};
const handleBreadthChange = (text) => {
setBreadth(text);
};
return (
<View style={globalStyles.container}>
<ScrollView>
<Card>
<Dimension
length={length}
breadth={breadth}
handleLengthChange={handleLengthChange}
handleBreadthChange={handleBreadthChange}
/>
<QualitySelector />
<Rate />
</Card>
<Card>
<Result totalCost={totalCost} />
</Card>
</ScrollView>
<View style={globalStyles.absoluteButton}>
<FlatButton />
</View>
</View>
);
}
export default function Dimension({
length,
breadth,
handleLengthChange,
handleBreadthChange
}) {
return (
<View style={styles.sectionContainer}>
<Text style={globalStyles.sectionTitle}>Dimension</Text>
<View style={styles.sectionOption}>
<Text style={globalStyles.inputTitle}>Length</Text>
<TextInput
value={length}
style={{ ...globalStyles.inputField, ...styles.inputField }}
keyboardType="numeric"
onChangeText={(text) => handleLengthChange(text)}
/>
<Text style={styles.inputUnit}>meter</Text>
</View>
<View style={styles.sectionOption}>
<Text style={globalStyles.inputTitle}>Breadth</Text>
<TextInput
value={breadth}
style={{ ...globalStyles.inputField, ...styles.inputField }}
keyboardType="numeric"
onChangeText={(text) => handleBreadthChange(text)}
/>
<Text style={styles.inputUnit}>meter</Text>
</View>
</View>
);
}
我正在用 expo 构建一个项目。我的项目恰好有一个表单字段,但我没有使用任何库来处理表单。每当我尝试点击其中一个 TextInput 字段时,键盘会立即出现并立即消失。但在那之后,如果我在输入字段中再次点击,键盘将保留在屏幕上。我似乎无法弄清楚问题是什么。我在 google 上搜索了很多,但没有一个结果讨论我提到的问题。
发现问题仅针对我的设备。可能是世博会中的某种错误。如果有人遇到同样的问题,请尝试 运行 在多台设备上安装您的应用。如果问题仍然存在,请弹出您的项目并 运行 使用裸反应本机。
export default function HomeScreen() {
const [length, setLength] = useState("");
const [breadth, setBreadth] = useState("");
const [totalCost, setTotalCost] = useState("0");
const handleLengthChange = (text) => {
setLength(text);
};
const handleBreadthChange = (text) => {
setBreadth(text);
};
return (
<View style={globalStyles.container}>
<ScrollView>
<Card>
<Dimension
length={length}
breadth={breadth}
handleLengthChange={handleLengthChange}
handleBreadthChange={handleBreadthChange}
/>
<QualitySelector />
<Rate />
</Card>
<Card>
<Result totalCost={totalCost} />
</Card>
</ScrollView>
<View style={globalStyles.absoluteButton}>
<FlatButton />
</View>
</View>
);
}
export default function Dimension({
length,
breadth,
handleLengthChange,
handleBreadthChange
}) {
return (
<View style={styles.sectionContainer}>
<Text style={globalStyles.sectionTitle}>Dimension</Text>
<View style={styles.sectionOption}>
<Text style={globalStyles.inputTitle}>Length</Text>
<TextInput
value={length}
style={{ ...globalStyles.inputField, ...styles.inputField }}
keyboardType="numeric"
onChangeText={(text) => handleLengthChange(text)}
/>
<Text style={styles.inputUnit}>meter</Text>
</View>
<View style={styles.sectionOption}>
<Text style={globalStyles.inputTitle}>Breadth</Text>
<TextInput
value={breadth}
style={{ ...globalStyles.inputField, ...styles.inputField }}
keyboardType="numeric"
onChangeText={(text) => handleBreadthChange(text)}
/>
<Text style={styles.inputUnit}>meter</Text>
</View>
</View>
);
}
我正在用 expo 构建一个项目。我的项目恰好有一个表单字段,但我没有使用任何库来处理表单。每当我尝试点击其中一个 TextInput 字段时,键盘会立即出现并立即消失。但在那之后,如果我在输入字段中再次点击,键盘将保留在屏幕上。我似乎无法弄清楚问题是什么。我在 google 上搜索了很多,但没有一个结果讨论我提到的问题。
发现问题仅针对我的设备。可能是世博会中的某种错误。如果有人遇到同样的问题,请尝试 运行 在多台设备上安装您的应用。如果问题仍然存在,请弹出您的项目并 运行 使用裸反应本机。