Подтвердить что ты не робот

Сделайте элемент палкой на дно, используя flex в реагировании

Предположим, что это макет:

<View style={styles.container}>
    <View style={styles.titleWrapper}>
        ...
        ...
    </View>
    <View style={styles.inputWrapper}>
        ...
        ...
    </View>

    <View style={styles.footer}>
        <TouchableOpacity>
            <View style={styles.nextBtn}>
                <Text style={styles.nextBtnText}>Next</Text>
            </View>
        </TouchableOpacity>
    </View>
</View>

Я хочу, чтобы представление со стилями нижнего колонтитула располагалось в нижней части экрана. Я попытался предоставить свойство alignSelf нижнему колонтитулу, но вместо того, чтобы позиционировать снизу, он позиционирует его в правой части экрана. Как я могу сделать элемент нижнего колонтитула до конца? Спасибо.

4b9b3361

Ответ 1

В React Native значением по умолчанию flexDirection является column (в отличие от CSS, где он является row).

Следовательно, в flexDirection: 'column' поперечная ось горизонтальна и alignSelf работает влево/вправо.

Чтобы justifyContent: 'space-between' нижний колонтитул к нижней части, примените justifyContent: 'space-between' и контейнером

Ответ 2

Я бы использовал следующий подход:

<View style={styles.container}>

    <View style={styles.contentContainer}> {/* <- Add this */}

        <View style={styles.titleWrapper}>
            ...
        </View>
        <View style={styles.inputWrapper}>
            ...
        </View>

    </View>

    <View style={styles.footer}>
        ...
    </View>
</View>
var styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F5FCFF',
    },
    titleWrapper: {

    },
    inputWrapper: {

    },
    contentContainer: {
        flex: 1 // pushes the footer to the end of the screen
    },
    footer: {
        height: 100
    }
});

Таким образом, стили titleWrapper и inputWrapper могут быть обновлены без нарушения макета вашего приложения, а сами компоненты легче использовать повторно:)

Ответ 3

Абсолютная позиция - это еще один способ исправить нижний колонтитул, как:

footer: {
    position: 'absolute',
    height: 40,
    left: 0, 
    top: WINDOW_HEIGHT - 40, 
    width: WINDOW_WIDTH,
 }

Ответ 4

Для этого вы можете использовать положение элемента таблицы стилей: "абсолютный".

/*This is an Example to Align a View at the Bottom of Screen in React Native */
import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';
export default class App extends Component {
  render() {
    return (
      <View style={styles.containerMain}>
        <Text> Main Content Here</Text>
        <View style={styles.bottomView}>
          <Text style={styles.textStyle}>Bottom View</Text>
        </View>
      </View>
    );
  }
}
const styles = StyleSheet.create({
  containerMain: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  bottomView: {
    width: '100%',
    height: 50,
    backgroundColor: '#EE5407',
    justifyContent: 'center',
    alignItems: 'center',
    position: 'absolute', //Here is the trick
    bottom: 0, //Here is the trick
  },
  textStyle: {
    color: '#fff',
    fontSize: 18,
  },
});

enter image description here

Ответ 5

вставлять другой контент в scrollview

<View style={styles.container}>

  <ScrollView> {/* <- Add this */}
        <View style={styles.titleWrapper}>
            ...
        </View>
        <View style={styles.inputWrapper}>
            ...
        </View>
    </ScrollView>

    <View style={styles.footer}>
        ...
    </View>
</View>    

Ответ 6

В реакции native есть некоторые свойства, такие как position: 'absolute', bottom: 0, которые вы захотите дать своему виду кнопок