parent
cd5b8db8db
commit
2ba5602b27
@ -1,41 +1,45 @@ |
|||||||
import { Tabs } from "expo-router"; |
import { Tabs } from "expo-router"; |
||||||
import { MaterialIcons } from "@expo/vector-icons"; |
import { MaterialIcons } from "@expo/vector-icons"; |
||||||
|
import { TodosProvider } from "@/store/todoProvider"; |
||||||
|
|
||||||
export default function TabLayout() { |
export default function TabLayout() { |
||||||
return ( |
return ( |
||||||
<Tabs |
<TodosProvider> |
||||||
screenOptions={{ |
<Tabs |
||||||
headerShown: false, |
screenOptions={{ |
||||||
tabBarStyle: { height: 56 }, |
headerShown: false, |
||||||
tabBarLabelStyle: { fontSize: 12 }, |
tabBarStyle: { height: 56 }, |
||||||
}} |
tabBarLabelStyle: { fontSize: 12 }, |
||||||
> |
tabBarHideOnKeyboard: true, |
||||||
<Tabs.Screen |
|
||||||
name="index" |
|
||||||
options={{ |
|
||||||
title: "할 일", |
|
||||||
tabBarIcon: ({ color, focused, size }) => ( |
|
||||||
<MaterialIcons |
|
||||||
name={focused ? "check-box" : "check-box-outline-blank"} |
|
||||||
size={size ?? 24} |
|
||||||
color={color} |
|
||||||
/> |
|
||||||
), |
|
||||||
}} |
}} |
||||||
/> |
> |
||||||
<Tabs.Screen |
<Tabs.Screen |
||||||
name="done" |
name="index" |
||||||
options={{ |
options={{ |
||||||
title: "완료됨", |
title: "할 일", |
||||||
tabBarIcon: ({ color, focused, size }) => ( |
tabBarIcon: ({ color, focused, size }) => ( |
||||||
<MaterialIcons |
<MaterialIcons |
||||||
name={focused ? "done-all" : "done"} |
name={focused ? "check-box" : "check-box-outline-blank"} |
||||||
size={size ?? 24} |
size={size ?? 24} |
||||||
color={color} |
color={color} |
||||||
/> |
/> |
||||||
), |
), |
||||||
}} |
}} |
||||||
/> |
/> |
||||||
</Tabs> |
<Tabs.Screen |
||||||
|
name="done" |
||||||
|
options={{ |
||||||
|
title: "완료됨", |
||||||
|
tabBarIcon: ({ color, focused, size }) => ( |
||||||
|
<MaterialIcons |
||||||
|
name={focused ? "done-all" : "done"} |
||||||
|
size={size ?? 24} |
||||||
|
color={color} |
||||||
|
/> |
||||||
|
), |
||||||
|
}} |
||||||
|
/> |
||||||
|
</Tabs> |
||||||
|
</TodosProvider> |
||||||
); |
); |
||||||
} |
} |
||||||
|
@ -1,5 +1,31 @@ |
|||||||
|
import TodoList from "@/components/TodoList"; |
||||||
|
import { Button, ButtonText } from "@/components/ui/button"; |
||||||
|
import { GS } from "@/components/ui/gluestack-ui-provider/gluestack-ui-token"; |
||||||
|
import { HStack } from "@/components/ui/hstack"; |
||||||
|
import { Text } from "@/components/ui/text"; |
||||||
|
import { VStack } from "@/components/ui/vstack"; |
||||||
|
import { useTodosCtx } from "@/store/todoProvider"; |
||||||
import { SafeAreaView } from "react-native-safe-area-context"; |
import { SafeAreaView } from "react-native-safe-area-context"; |
||||||
|
|
||||||
export default function DoneTab() { |
export default function DoneTab() { |
||||||
return <SafeAreaView className="flex-1"></SafeAreaView>; |
const { doneTodos, toggle, remove, clearDone } = useTodosCtx(); |
||||||
|
|
||||||
|
return ( |
||||||
|
<SafeAreaView className="flex-1 bg-white dark:bg-neutral-900"> |
||||||
|
<VStack className="flex-1 px-4 py-1 gap-3"> |
||||||
|
<Text className="text-2xl font-bold">완료한 일</Text> |
||||||
|
<TodoList data={doneTodos} onToggle={toggle} onRemove={remove} /> |
||||||
|
<HStack className="justify-end"> |
||||||
|
<Button |
||||||
|
className="flex-1" |
||||||
|
variant={GS.variant.outline} |
||||||
|
action={GS.action.secondary} |
||||||
|
onPress={clearDone} |
||||||
|
> |
||||||
|
<ButtonText>완료한 일 모두 지우기</ButtonText> |
||||||
|
</Button> |
||||||
|
</HStack> |
||||||
|
</VStack> |
||||||
|
</SafeAreaView> |
||||||
|
); |
||||||
} |
} |
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,23 @@ |
|||||||
|
import { createContext, useContext } from "react"; |
||||||
|
import { type Todo, useTodos } from "./useTodos"; |
||||||
|
|
||||||
|
type TodosContextValue = ReturnType<typeof useTodos>; |
||||||
|
|
||||||
|
const TodosContext = createContext<TodosContextValue | null>(null); |
||||||
|
|
||||||
|
export function TodosProvider({ children }: { children: React.ReactNode }) { |
||||||
|
const store = useTodos(); |
||||||
|
return ( |
||||||
|
<TodosContext.Provider value={store}>{children}</TodosContext.Provider> |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
export function useTodosCtx(): TodosContextValue { |
||||||
|
const ctx = useContext(TodosContext); |
||||||
|
if (!ctx) { |
||||||
|
throw new Error("use TodosCtx must be used within <TodosProvider>"); |
||||||
|
} |
||||||
|
return ctx; |
||||||
|
} |
||||||
|
|
||||||
|
export type { Todo }; |
Loading…
Reference in new issue