问题描述
好的,所以我有一个工作的应用程序,该应用程序在textInput
中获取了一些文本并更改了状态,并返回了一些alert
和符合这些条件的Object.keys
。
import React from 'react';
import {imagebackground,Image,TouchableOpacity,TextInput,Text,View,Keyboard,} from 'react-native';
import styles from "./comp/styles.js"
import listadoPrep from "./comp/list.json";
var logo = require ('./assets/icon.png');
class App extends React.Component{
constructor(){
super();
this.state={
sueldo:'',}
}
submit(){
for (let key of Object.keys(listadoPrep)) {
if(this.state.sueldo <= listadoPrep[key][0]) {
alert(key);
}
}
}
render(){
return (
<View style={styles.container}>
<imagebackground source={require("./assets/background.png")} style={styles.background}>
<View style={styles.body}>
<Image source={logo}/>
<Text style={styles.text}>¿Cuál es tu sueldo bruto?</Text>
<TextInput style={styles.textInput}
placeholder="No hace falta que sea exacto,podés redondear ?"
maxLength={6}
onBlur={Keyboard.dismiss}
value={this.state.sueldo}
onChangeText={(text)=>{this.setState({sueldo:text})}}/>
<View style={styles.inputContainer}>
<TouchableOpacity style={styles.saveButton}
onPress={()=>{this.submit()}}>
<Text style={styles.saveButtonText}>Siguiente</Text>
</TouchableOpacity>
</View>
</View>
</imagebackground>
</View>
);
}
}
export default App;
,然后我尝试添加一些堆栈导航器,但是我无法设法使Class
在任何地方都能工作。我相信Class
是制作Constructor
所必需的,但是我对这个概念还不太了解。
import React from 'react';
import {imagebackground,} from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import styles from "./comp/styles.js"
import listadoPrep from "./comp/list.json";
var logo = require ('./assets/icon.png');
function HomeScreen() {
return (
<View style={{ flex: 1,alignItems: 'center',justifyContent: 'center' }}>
</View>
);
}
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
export default App;
我只是不知道如何将在上一个应用程序中已经完成的工作导入此StackNavigator
。我现在将研究有关构造函数的更多信息
解决方法
您现在有了一个新的app.js,它将作为您应用程序的起点。
因此,只需将Class App重命名为Class HomeScreen,即可在如下所示的堆栈导航器中使用它
{'type': 'track','event': 'active','properties': {'new': 'ABC883322'
},'options': {'target': 'bottomNext'
},'userId': None,'anonymousId': 'c7ccc67e-f7d4-4198-9cef-7d6895c1bd3b','meta': {'timestamp': 1603037276643
},'_': {'originalAction': 'track','called': 'track','from': 'engineEnd'
},'traits': {'lfid': 'foobar'
},'id': '20b1aab0-115c-11eb-9e18-b5713e730a08','lfid': 'foobar','partner_resid': '958791a0-e05d-4e01-a55a-da48e3ec3981'}
您可以为该类使用任何名称,您在此处提供的组件将显示在堆栈中
public class checkThread {
volatile int i = 0;
public void increment() {
i++;
}
}
public class TestSync extends checkThread{
public static void main(String[] args) {
checkThread ct1 = new checkThread();
Object iLock = new Object();
for(int i = 0 ; i < 10 ; i++) {
extracted(ct1,iLock);
}
}
private static void extracted(checkThread ct1,Object iLock) {
synchronized (iLock) {
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
for(int a = 0; a < 1000; a++) {
ct1.increment();
}
}
});
t1.start();
}
synchronized (iLock) {
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
for(int a = 0; a < 1000; a++) {
ct1.increment();
}
}
});
t2.start();
}
synchronized (iLock) {
System.out.println(ct1.i);
}
}
}