“items doesn’t stick to bottom react native” 可翻译为:”项目不粘在底部React Native”。

huangapple go评论52阅读模式
英文:

items doesnt stick to bottom react nativr

问题

我理解你想要的只是代码的中文翻译部分,以下是翻译好的代码部分:

im trying to make a to-do list in react native and im trying to make the input and plus bar stick to the bottom and make it go up when i open the keyboard. when i use padding the bar sticks to bottom but i want to use flexbox to make it compatible with all phones. can someone help make stick it to bottom and make it go up with keyboard

task.js

import React from 'react';
import { View, Text, SafeAreaView, StyleSheet, TextInput, KeyboardAvoidingView, TouchableWithoutFeedback, TouchableOpacity } from 'react-native';

const AddTask = () => {
    const handleAddTask = () => {
        Keyboard.dismiss();
        setTaskItems([...taskItems, task])
        setTask(null);
    }

    return (
        <KeyboardAvoidingView 
            behavior={Platform.OS === "ios" ? "padding" : "height"}
            style ={styles.inputbuttons}
        >
            <TextInput style={styles.input} placeholder={'写一个任务'}  />
            <TouchableOpacity onPress={() => handleAddTask()}>
                <View style = {styles.plus}>
                    <Text>+</Text>
                </View>
            </TouchableOpacity>
        </KeyboardAvoidingView>
    );
};

const styles = StyleSheet.create({
    input: {
        height: 60,
        width:320,
        margin: 12,
        borderWidth: 1,
        padding: 10,
        borderRadius:20,
    },
    inputbuttons: {
        flexDirection:'row',
        alignItems:'center',
        justifyContent:'flex-end'
    },
    plus: {
        width:60,
        height:60,
        borderWidth:1,
        borderColor:'black',
        textAlign:'right',
        borderRadius:'15',
        textAlign: 'center',
        justifyContent: 'center',
        fontSize:30
    }
});

export default AddTask;

app.js

import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button, Alert, Input } from 'react-native';
import Task from './components/Task';
import AddTask from './components/AddTask';

export default function App() {
    return (
        <View style={styles.container}>

            <View style = {styles.taskWrapper}>
                <Text style={styles.header}>今天的任务</Text>
            </View>

            <View style={styles.tasks}>
                <Task></Task>
                <Task></Task>
            </View>

            <View>
                <AddTask></AddTask>
            </View>
        </View>
    );
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#E8EAED',
    },
    taskWrapper: {
        paddingTop: 80,
        paddingHorizontal: 20
    },
    header: {
        fontSize: 24,
        fontWeight:'bold'
    },
    tasks: {

    },
});

希望这对你有所帮助。如果有任何其他问题,请随时告诉我。

英文:

im trying to make a to-do list in react native and im trying to make the input and plus bar stick to the bottom and make it go up when i open the keyboard. when i use padding the bar sticks to bottom but i want to use flexbox to make it compatible with all phones. can someone help make stick it to bottom and make it go up with keyboard

task.js

    import React from &#39;react&#39;;
import {View, Text, SafeAreaView, StyleSheet, TextInput,KeyboardAvoidingView, TouchableWithoutFeedback, TouchableOpacity} from &#39;react-native&#39;;
const AddTask = () =&gt; {
const handleAddTask = () =&gt; {
Keyboard.dismiss();
setTaskItems([...taskItems, task])
setTask(null);
}
return (
&lt;KeyboardAvoidingView 
behavior={Platform.OS === &quot;ios&quot; ? &quot;padding&quot; : &quot;height&quot;}
style ={styles.inputbuttons}
&gt;
&lt;TextInput style={styles.input} placeholder={&#39;Write a task&#39;}  /&gt;
&lt;TouchableOpacity onPress={() =&gt; handleAddTask()}&gt;
&lt;View style = {styles.plus}&gt;
&lt;Text&gt;+&lt;/Text&gt;
&lt;/View&gt;
&lt;/TouchableOpacity&gt;
&lt;/KeyboardAvoidingView&gt;
);
};
const styles = StyleSheet.create({
input: {
height: 60,
width:320,
margin: 12,
borderWidth: 1,
padding: 10,
borderRadius:20,
},
inputbuttons:{
flexDirection:&#39;row&#39;,
alignItems:&#39;center&#39;,
justifyContent:&#39;flex-end&#39;
},
plus:{
width:60,
height:60,
borderWidth:1,
borderColor:&#39;black&#39;,
textAlign:&#39;right&#39;,
borderRadius:&#39;15&#39;,
textAlign: &#39;center&#39;,
justifyContent: &#39;center&#39;,
fontSize:30
}
});
export default AddTask;

app.js

import { StatusBar } from &#39;expo-status-bar&#39;;
import { StyleSheet, Text, View,Button, Alert,Input } from &#39;react-native&#39;;
import Task from &#39;./components/Task&#39;;
import AddTask from &#39;./components/AddTask&#39;;
export default function App() {
return (
&lt;View style={styles.container}&gt;
&lt;View style = {styles.taskWrapper}&gt;
&lt;Text style={styles.header}&gt;Today&#39;s Tasks&lt;/Text&gt;
&lt;/View&gt;
&lt;View style={styles.tasks}&gt;
&lt;Task&gt;&lt;/Task&gt;
&lt;Task&gt;&lt;/Task&gt;
&lt;/View&gt;
&lt;View&gt;
&lt;AddTask&gt;&lt;/AddTask&gt;
&lt;/View&gt;
&lt;/View&gt;
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: &#39;#E8EAED&#39;,
},
taskWrapper:{
paddingTop:80,
paddingHorizontal:20
},
header:{
fontSize:24,
fontWeight:&#39;bold&#39;
},
tasks:{
},
});

答案1

得分: 0

你应该在你的应用组件中使用KeyboardAvoidingView,这样每当键盘激活时,App组件就会被推动。

英文:

You should use KeyboardAvoidingView in your app component so that whenever keyboard gets activated then the component of App gets pushed.

huangapple
  • 本文由 发表于 2023年2月18日 17:01:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75492253.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定