#javascript #reactjs #react-native
#javascript #reactjs #react-native
Вопрос:
Привет, ребята, я работаю над проектом React Native. Я новичок в программировании / React Native. Я не знаю, как поместить поле textinput в мой модальный на App.js . хотите создать текстовое сообщение электронной почты внутри этого модального, нужны некоторые рекомендации и инструкции. Помогите!
https://reactnative.dev/docs/textinput это пример, которому я следую. Я вставляю его в свой app.js но это не работает.
import { StatusBar } from "expo-status-bar"; import React, { Component } from "react"; import { StyleSheet, Text, View, Modal, Button, Alert } from "react-native"; import UselessTextInput from "./components/TextInputComponent"; import Main from "./components/MainComponent"; import * as Font from "expo-font";
// const getFonts = () => // Font.loadAsync({ // "nunito-regular": require("./assets/fonts/Nunito-Regular.ttf"), // "nunito-bold": require("./assets/fonts/Nunito-Bold.ttf"), // });
class App extends Component { constructor(props) {
super(props);
this.state = {
fontsLoaded: false,
showModal: false,
}; }
async loadFonts() {
await Font.loadAsync({
// Load a font `Montserrat` from a static resource
"Nunito-Bold": require("./assets/fonts/Nunito-Bold.ttf"),
// Any string can be used as the fontFamily name. Here we use an object to provide more control
"Nunito-SemiBold": {
uri: require("./assets/fonts/Nunito-SemiBold.ttf"),
display: Font.FontDisplay.FALLBACK,
},
});
this.setState({ fontsLoaded: true }); } componentDidMount() {
this.loadFonts(); } render() {
return (
<View style={{ flex: 1, marginTop: 100 }}>
<Button
title="More recipes Click Here"
onPress={() => {
this.setState({ showModal: true });
}}
/>
<Main />
<Modal transparent={true} visible={this.state.showModal}>
<View style={{ backgroundColor: "#000000aa" }}>
<View
style={{
backgroundColor: "#ffffff",
margin: 50,
padding: 40,
borderRadius: 10,
}}
>
<Text style={{ fontSize: 50 }}>Modal Text</Text>
<Button
title="No, Thanks."
onPress={() => {
this.setState({ showModal: false });
}}
/>
</View>
</View>
</Modal>
</View>
); } } export default App; const styles = StyleSheet.create({ container: {
flex: 1,
fontFamily: "Nunito-SemiBold",
alignItems: "center",
justifyContent: "center", }, }); ```
Комментарии:
1. Где находится текстовый ввод?
Ответ №1:
Просто импортируйте из react-native и вставьте в модальный as simple может помочь в этом.
import {
TextInput,
} from 'react-native';
....
<Modal transparent={true} visible={this.state.showModal}>
...
<TextInput
style={styles.input}
placeholder="useless placeholder"
keyboardType="numeric"
/>
....
</Model>
const styles = StyleSheet.create({
input: {
height: 40,
margin: 12,
borderWidth: 1,
},
});