Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Dynamic Styles In React Native


export default function App() {
  const [r, setR] = useState(true);

  
    return (
    <View style={styles.container}>

<TouchableOpacity style={[styles.button, {backgroundColor: r? "blue":"yellow"}]}>
<Text style={{color:  r? "black":"blue"}}>
 Invoke Fancy Button
  </Text>

</TouchableOpacity> 

    </View>
  );
}

/*keep in mind you must keep your dynamic styling separate from your static stuff*/
Comment

react native dynamic style

//you can use a function to generate a styleSheet dynamically
styleFunction (option) {
  return {
    borderWidth: 2,
    margin: option,
  }
}

<View style={this.styleFunction(15)}>
	//things
</View>
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript promise example 
Javascript :: window location href 
Javascript :: react onsubmit get form values 
Javascript :: js return 
Javascript :: fs.writefile promise 
Javascript :: sort list in javascript 
Javascript :: call bind apply in javascript 
Javascript :: how to remove duplicates in js 
Javascript :: Remove uploaded file in jquery 
Javascript :: hello world in react 
Javascript :: ajax post request 
Javascript :: color switcher 
Javascript :: js pick last element of array 
Javascript :: open in new tab js html does not work on iphone 
Javascript :: p cannot appear as a descendant of p react 
Javascript :: eager loading 
Javascript :: navlink react active class 
Javascript :: javascript for...of with Sets 
Javascript :: django debug toolbar javascript error 
Javascript :: ejs split string 
Javascript :: how to divide a month into weeks in moment js 
Javascript :: mongoose schema index of multiple columns 
Javascript :: regex tunisian phone number 
Javascript :: phaser chained animation 
Javascript :: Horizontal scroll to anchor 
Javascript :: on click insert into element time 
Javascript :: javascript to jquery code converter online 
Javascript :: Get index of child elements with event listener in JavaScript 
Javascript :: ternary operators js 
Javascript :: comentar en javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =