Docsity
Trusted Seller

React native - input text, Appunti di Sviluppo di Applicazioni Web

Toggle sidebar
bg1
Input text 1
Input text
ClassApp.js
import React from "react";
import {
Button,
StyleSheet,
Text,
TextInput,
View,
SafeAreaView,
} from "react-native";
import { CustomButton } from "./src/components/CustomButton";
import InputField from "./src/components/InputField";
// render 2
// constructor 1
// componentDidMount 3
// componentWillUnmount 5 Quando viene dismesso
// componentDidUpdate 4 Ma ogni volta che il render si aggiorna
export default class ClassApp extends React.Component {
constructor(props) {
super(props);
this.state = {
label: "CIAO",
title: "BUTTON",
disabled: false,
input: "TESTO",
};
}
pf3
pf4
pf5

Anteprima parziale del testo

Scarica React native - input text e più Appunti in PDF di Sviluppo di Applicazioni Web solo su Docsity!

Input text

ClassApp.js

import React from "react"; import { Button, StyleSheet, Text, TextInput, View, SafeAreaView, } from "react-native"; import { CustomButton } from "./src/components/CustomButton"; import InputField from "./src/components/InputField";

// render 2 // constructor 1 // componentDidMount 3 // componentWillUnmount 5 Quando viene dismesso // componentDidUpdate 4 Ma ogni volta che il render si aggiorna

export default class ClassApp extends React.Component { constructor(props) { super(props); this.state = { label: "CIAO", title: "BUTTON", disabled: false, input: "TESTO", }; }

componentDidMount() { setTimeout(() => { this.setState({ title: "NOTTUB" }); }, 4000); }

onPress = () => { console.log("onPress"); };

onChangeText = (text) => { this.setState({ input: text }); };

render() { return ( {this.state.label} <InputField onChangeText={this.onChangeText} placeholder="Inserisci il testo" value={this.state.input} isSecure={true} style={{ marginBottom: 20 }} /> <CustomButton onPress={() => { this.setState({ disabled: !this.state.disabled }); // this.setState((prevState) => ({ disabled: !prevState.disabled })) }} title="Set disabled" disabled={false} /> <TextInput onChangeText={(text) => console.log(text)} /> ); }

componentWillUnmount() {}

componentDidUpdate(prevProps, prevState) { console.log("componentDidUpdate", this.state.input); } }

{title} ); } }

//stile del bottone const styles = StyleSheet.create({ container: { alignItems: 'center', backgroundColor: 'red', shadowColor: "#000", shadowOffset: { width: 0, height: 3, }, shadowOpacity: 0.29, shadowRadius: 4.65, elevation: 7, padding: 10, borderRadius: 10, }, });

src → components → InputFields.js

import React, { Component } from 'react'; import {TextInput, StyleSheet} from "react-native";

class InputField extends Component { render() { return ( <TextInput onChangeText={this.props.onChangeText} value={this.props.value} style={[styles.input, this.props.style]} placeholder={this.props.placeholder} secureTextEntry={this.props.isSecure} /> ); } }

const styles = StyleSheet.create({ input: { height: 50, borderWidth: 1, borderRadius: 8,

fontSize: 16, paddingHorizontal: 16, } });

export default InputField;