React Native - 按钮样式问题

React Native - Button Styling Issues

我很困惑为什么我的按钮看起来不像默认的本机 React 按钮,方形形状跨越视口的最大宽度 - 我已经研究并从 React 文档中了解到本机按钮在样式和道具方面非常有限,但我的似乎缺少默认样式 - 有什么提示吗?我的按钮组件可以找到here

我已经尝试将 backgroundColor 添加到样式、颜色等,但没有任何变化

试试这个...根据需要进一步自定义 在这之后你会喜欢 react-native 和 to style :)

import React, { useState } from "react";
import { StyleSheet, View, TextInput, TouchableOpacity } from "react-native";

export default function AddTodo({ submitHandler }) {
  const [text, setText] = useState("");
  const changeHandler = (val) => {
    setText(val);
  };

  return (
    <View>
      <TextInput
        style={styles.input}
        placeholder="add a game to the docket..."
        placeholderTextColor="white"
        onChangeText={changeHandler}
        clearTextOnFocus="true"
      />
      <TouchableOpacity style={styles.btn} onPress={() => submitHandler(text)}>
        <Text style={styles.btnText}>add game</Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  input: {
    marginBottom: 10,
    paddingHorizontal: 8,
    paddingVertical: 6,
    backgroundColor: "#2DCCCF",
    flexDirection: "row",
    color: "white",
  },
  btn: {
    height: 45,
    borderRadius: 8,
    elevation: 3,
    backgroundColor: "#AB47BC",
    justifyContent: "center",
  },
  btnText: {
    color: "#fff",
  },
});