[RN 3-4 프로젝트 개발 3]

2020. 2. 22. 10:46React Native/React Native 일정관리 앱

반응형

11) AddTodo 컴포넌트


src/Screens/Todo/AddTodo/

index.tsx

 

더보기
import React, { useState } from 'react';

import AddButton from './AddButton';
import TodoInput from './TodoInput';

interface Props {}

const AddTodo = ({  }: Props) => {
  const [showInput, setShowInput] = useState<boolean>(false);
  return (
    <>
      <AddButton onPress={() => setShowInput(true)} />
      {showInput && <TodoInput hideTodoInput={() => setShowInput(false)} />}
    </>
  );
};
export default AddTodo;

 


12) AddButton 컴포넌트


src/Screens/Todo/AddTodo/AddButton/

index.tsx

 

더보기
import React from 'react';
import Styled from 'styled-components/native';

const Container = Styled.SafeAreaView`
  position: absolute;
  bottom: 0;
  align-self: center;
  justify-content: flex-end;
`;
const ButtonContainer = Styled.TouchableOpacity`
  box-shadow: 4px 4px 8px #999;
`;
const Icon = Styled.Image``;

interface Props {
  onPress?: () => void;
}

const AddButton = ({ onPress }: Props) => {
  return (
    <Container>
      <ButtonContainer onPress={onPress}>
        <Icon source={require('~/Assets/Images/add.png')} />
      </ButtonContainer>
    </Container>
  );
};
export default AddButton;

 


13) TodoInput 컴포넌트


src/Screens/Todo/AddTodo/TodoInput/

index.tsx

 

더보기
import React from 'react';
import Styled from 'styled-components/native';

import Background from './Background';
import TextInput from './TextInput';

const Container = Styled.KeyboardAvoidingView`
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  justify-content: flex-end;
`;

interface Props {
  hideTodoInput: () => void;
}

const TodoInput = ({ hideTodoInput }: Props) => {
  return (
    <Container behavior="padding">
      <Background onPress={hideTodoInput} />
      <TextInput hideTodoInput={hideTodoInput} />
    </Container>
  );
};
export default TodoInput;

 


14) Background 컴포넌트


src/Screens/Todo/AddTodo/TodoInput/Background/

index.tsx

 

더보기
import React from 'react';
import Styled from 'styled-components/native';

const Container = Styled.TouchableWithoutFeedback`
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
`;

const BlackBackground = Styled.View`
  background-color: #000;
  opacity: 0.3;
  width: 100%;
  height: 100%;
`;

interface Props {
  onPress: () => void;
}

const Background = ({ onPress }: Props) => {
  return (
    <Container onPress={onPress}>
      <BlackBackground />
    </Container>
  );
};
export default Background;

15) Context에 데이터를 추가하는 TextInput 컴포넌트


src/Screens/Todo/AddTodo/TodoInput/TextInput/

index.tsx

 

더보기
import React, { useContext } from 'react';
import Styled from 'styled-components/native';

import { TodoListContext } from '~/Context/TodoListContext';

const Input = Styled.TextInput`
  width: 100%;
  height: 40px;
  background-color: #FFF;
  padding: 0px 8px;
`;

interface Props {
  hideTodoInput: () => void;
}

const TextInput = ({ hideTodoInput }: Props) => {
  const { addTodoList } = useContext<ITodoListContext>(TodoListContext);
  return (
    <Input
      autoFocus={true}
      autoCapitalize="none"
      autoCorrect={false}
      placeholder="할일을 입력하세요!"
      returnKeyType="done"
      onSubmitEditing={({ nativeEvent }) => {
        addTodoList(nativeEvent.text);
        hideTodoInput();
      }}
    />
  );
};
export default TextInput;

 


TodoList 소스파일(src)

(*) 앱 종료시 데이터 휘발성으로 없어짐

src.zip
0.01MB

 

반응형

'React Native > React Native 일정관리 앱' 카테고리의 다른 글

[RN 3-3 프로젝트 개발 2]  (0) 2020.02.22
[RN 3-2 프로젝트 개발 1]  (0) 2020.02.21
[RN 3-1 프로젝트 준비]  (0) 2020.02.21