Slight restructure, basic navigation
This commit is contained in:
parent
cdb110a19f
commit
afe511b448
3 changed files with 37 additions and 44 deletions
29
App.tsx
29
App.tsx
|
@ -1,5 +1,4 @@
|
||||||
import { StatusBar } from "expo-status-bar";
|
import { StatusBar } from "expo-status-bar";
|
||||||
import { View } from "react-native";
|
|
||||||
import { style } from "./src/util/style";
|
import { style } from "./src/util/style";
|
||||||
|
|
||||||
import { PostsContainer } from "./src/components/PostsContainer";
|
import { PostsContainer } from "./src/components/PostsContainer";
|
||||||
|
@ -17,34 +16,22 @@ export default function App(): JSX.Element {
|
||||||
<Stack.Navigator>
|
<Stack.Navigator>
|
||||||
<Stack.Screen
|
<Stack.Screen
|
||||||
name="Home"
|
name="Home"
|
||||||
component={HomeScreen}
|
component={PostsContainer}
|
||||||
options={homeOptions}
|
options={options}
|
||||||
|
/>
|
||||||
|
<Stack.Screen
|
||||||
|
name="New"
|
||||||
|
options={options}
|
||||||
|
component={NewPostContainer}
|
||||||
/>
|
/>
|
||||||
<Stack.Screen name="New" component={PostScreen} />
|
|
||||||
</Stack.Navigator>
|
</Stack.Navigator>
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const homeOptions = {
|
const options = {
|
||||||
headerStyle: style.header,
|
headerStyle: style.header,
|
||||||
headerTitleStyle: style.headerTitle,
|
headerTitleStyle: style.headerTitle,
|
||||||
headerTintColor: "#fff",
|
headerTintColor: "#fff",
|
||||||
};
|
};
|
||||||
|
|
||||||
function HomeScreen(): JSX.Element {
|
|
||||||
return (
|
|
||||||
<View style={style.app}>
|
|
||||||
<PostsContainer />
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function PostScreen(): JSX.Element {
|
|
||||||
return (
|
|
||||||
<View style={style.app}>
|
|
||||||
<NewPostContainer />
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { View, Text, TextInput, Button } from "react-native";
|
||||||
import { style } from "../util/style";
|
import { style } from "../util/style";
|
||||||
import { createPost, NewPost } from "../util/api";
|
import { createPost, NewPost } from "../util/api";
|
||||||
|
|
||||||
export function NewPostContainer(): JSX.Element {
|
export function NewPostContainer({ navigation }): JSX.Element {
|
||||||
const [currentInput, setCurrentInput] = React.useState<string>("");
|
const [currentInput, setCurrentInput] = React.useState<string>("");
|
||||||
const [currentInputError, setCurrentInputError] = React.useState<string>("");
|
const [currentInputError, setCurrentInputError] = React.useState<string>("");
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { RefreshControl } from "react-native";
|
import { Button, RefreshControl } from "react-native";
|
||||||
import { getPostsInterval, Post } from "../util/api";
|
import { getPostsInterval, Post } from "../util/api";
|
||||||
import { PostView } from "./PostView";
|
import { PostView } from "./PostView";
|
||||||
import { style } from "../util/style";
|
import { style } from "../util/style";
|
||||||
import { SafeAreaView } from "react-native";
|
import { SafeAreaView } from "react-native";
|
||||||
import { VirtualizedList } from "react-native";
|
import { VirtualizedList } from "react-native";
|
||||||
|
|
||||||
export function PostsContainer(): JSX.Element {
|
export function PostsContainer({ navigation }): JSX.Element {
|
||||||
const [postData, setPostData] = React.useState<Post[]>([]);
|
const [postData, setPostData] = React.useState<Post[]>([]);
|
||||||
const [page, setPage] = React.useState<number>(0);
|
const [page, setPage] = React.useState<number>(0);
|
||||||
const [refreshing, setRefreshing] = React.useState<boolean>(false);
|
const [refreshing, setRefreshing] = React.useState<boolean>(false);
|
||||||
|
@ -53,26 +53,32 @@ export function PostsContainer(): JSX.Element {
|
||||||
|
|
||||||
const getItem = (_data: unknown, index: number): Post => postData[index];
|
const getItem = (_data: unknown, index: number): Post => postData[index];
|
||||||
return (
|
return (
|
||||||
<SafeAreaView style={style.postsContainer}>
|
<>
|
||||||
<VirtualizedList
|
<Button
|
||||||
data={postData}
|
title="Go to Details"
|
||||||
initialNumToRender={4}
|
onPress={() => navigation.navigate("New")}
|
||||||
renderItem={({ item }) => (
|
|
||||||
<PostView key={item.id + item.createdAt} post={item} />
|
|
||||||
)}
|
|
||||||
keyExtractor={(item: Post) => item.id + item.createdAt}
|
|
||||||
getItemCount={getItemCount}
|
|
||||||
getItem={getItem}
|
|
||||||
onEndReached={handleEndReached}
|
|
||||||
onEndReachedThreshold={0.4}
|
|
||||||
refreshControl={
|
|
||||||
<RefreshControl
|
|
||||||
refreshing={refreshing}
|
|
||||||
onRefresh={onRefresh}
|
|
||||||
colors={["#007AFF"]}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
</SafeAreaView>
|
<SafeAreaView style={style.postsContainer}>
|
||||||
|
<VirtualizedList
|
||||||
|
data={postData}
|
||||||
|
initialNumToRender={4}
|
||||||
|
renderItem={({ item }) => (
|
||||||
|
<PostView key={item.id + item.createdAt} post={item} />
|
||||||
|
)}
|
||||||
|
keyExtractor={(item: Post) => item.id + item.createdAt}
|
||||||
|
getItemCount={getItemCount}
|
||||||
|
getItem={getItem}
|
||||||
|
onEndReached={handleEndReached}
|
||||||
|
onEndReachedThreshold={0.4}
|
||||||
|
refreshControl={
|
||||||
|
<RefreshControl
|
||||||
|
refreshing={refreshing}
|
||||||
|
onRefresh={onRefresh}
|
||||||
|
colors={["#007AFF"]}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</SafeAreaView>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue