Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16552

can't change background color of a button that's imported from react-native-paper

$
0
0

i am new to react native following a tutorial. I noticed there is no consistency of buttons between android and iOS so i thought i'd try react-native-paper library.

however, after importing the button from react-native-paper i am having problems changing the color of the button. the color is a constant color as in the image provided how the color looks

how can i manipulate the color? also is there a better library to use for button consistency between android and iOS ?

thanks

here is the code :

// import stuff
import React from 'react';
import { View, Text, TextInput, TouchableOpacity } from 'react-native';
import {
  Provider as PaperProvider,
  DarkTheme,
  DefaultTheme,
  Button
} from 'react-native-paper';
// import { Button } from 'react-native-paper';

//create stuff

class App extends React.Component {

  state = {
    text: "",
    todo: []
  }
  addTodo = () => {
    var newTodo = this.state.text
    var arr = this.state.todo
    arr.push(newTodo)
    this.setState({ todo: arr, text: "" })
  }

  deleteTodo = (t) => {
    var arr = this.state.todo;
    var pos = arr.indexOf(t);
    arr.splice(pos, 1);
    this.setState({ todo: arr });


  }

  renderTodos = () => {
    return this.state.todo.map(t => {
      return (
        <TouchableOpacity key={t}>
          <Text
            style={styles.todo}
            onPress={() => { this.deleteTodo(t) }}
          >{t}</Text>
        </TouchableOpacity>
      )
    })
  } 
  render() {
    return (
      <PaperProvider>
      <View style={styles.wholeStyle}>
        <View style={styles.viewStyle}>
          <Text style={styles.header}>Notes App</Text>
          <TextInput
            style={styles.inputStyle}
            onChangeText={(text) => this.setState({ text })}
            value={this.state.text}
          />
          <Button 
          onPress={this.addTodo}
          mode='contained'
          backgroundColor='black'>Todo</Button>
          {this.renderTodos()}
        </View>
      </View>
      </PaperProvider>
    )
  }
}

const styles = {
  wholeStyle: {
    flex: 1,
    backgroundColor: '#0288D1'
    // backgroundColor: 'red'
  },
  viewStyle: {
    alignItems: 'center',
    justifyContent: 'center',
    margin: 10,
    marginTop: 30,

  },
  inputStyle: {
    alignSelf: 'stretch',
    height: 40,
    borderColor: "white",
    borderWidth: 1

  },
  header: {
    fontSize: 40,
    color: 'white',
    fontWeight: 'bold'

  },
  todo: {
    fontSize: 18,
    color: 'white'
  }


}
//export stuff

export default App;

Viewing all articles
Browse latest Browse all 16552

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>