Why styled-component

설치

npm install --save styled-components

Import

import styled from "styled-components/native";

사용

import React from "react";
import { TouchableOpacity, Text } from "react-native";
import Stack from "../navigation/Stack";
import styled from "styled-components/native";

const Btn = styled.View`
  background-color: tomato;
`;

const Title = styled.Text`
  color: white;
`;

const Movies = ({ navigation: { navigate } }) => (
  <Btn
    style={{ flex: 1, justifyContent: "center", alignItems: "center" }}
    onPress={() => navigate(Stack, { screen: "one" })}
  >
    <Title>Movies</Title>
  </Btn>
);

export default Movies;

Props

기존 styled-component props 사용법과 완전히 같음

const Btn = styled.View`
  background-color: ${(props) => (props.selected ? "tomato" : "skyblue")};
`;

화면 기록 2022-04-24 오후 10.10.57.mov

Themes