๐Ÿ’ป[React Native] Style

ํ˜ฑยท2023๋…„ 1์›” 8์ผ

React Component-UI ์š”์†Œ
API- ์‹œ์Šคํ…œ ํ˜ธ์ถœ

import React from 'react';
import { Button, Text, View, StyleSheet } from 'react-native';

function singleNumber(props) {
  return (
    <view style={styles.circle}>
      <Text style={styles.label}>{props.number}</Text>
    </view>
  );
}


const styles = StyleSheet.create({
  circle: {
    width: 100,
    height: 100,
    backgroundColor: "#fff",
    justifyContent: 'center',
    alignItems: 'center'
  },
  label: {
    fontSize: 20,
    fontWeight: 'bold'
  }
});




export default singleNumber;

์›น์˜ CSS์™€ ์œ ์‚ฌ

View์— ์ ์šฉํ•  ์ˆ˜ ์žˆ๋Š” style: ViewStyle(๋”ฐ๋ผ์„œ textstyle์€ ์ ์šฉ ๋ถˆ๊ฐ€)

Styled-Component

props ๋„˜๊ฒจ ๋ฐ›๊ธฐ

const Circle = styled.View`
${(props) => {
  if (props.number < 11) {
    return 'background: yellow;';
  } else if (props.number < 21) {
    return 'background:blue;';
  }
}}
  `;

๋ณด๋‹ค react์Šค๋Ÿฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ๊ณ , ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ•˜๋Š” ์ผ๋“ค์ด ์ž‘์•„์ง€๊ฒŒ ๋จ

ImageBackground: source๋กœ ์ง€์ •

const Container = styled.ImageBackground`
flex:1;
justify-content: center;
align-items: center;
`;


<Container source={{url: 'https://placeimg.com/1280/1280/nature'}}resizeMode = {'stretch'}>
profile
new blog: https://hae0-02ni.tistory.com/

0๊ฐœ์˜ ๋Œ“๊ธ€