From d04a6d7539c53ec3510175459c1ca8c8e7e994da Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Thu, 26 Jan 2023 17:55:15 -0600 Subject: Add web layout components --- src/view/com/post-thread/PostThread.tsx | 11 +++--- src/view/com/posts/Feed.tsx | 17 +++++--- src/view/com/util/Views.tsx | 1 + src/view/com/util/Views.web.tsx | 70 +++++++++++++++++++++++++++++++++ src/view/shell/web/index.tsx | 24 +++++------ 5 files changed, 98 insertions(+), 25 deletions(-) create mode 100644 src/view/com/util/Views.tsx create mode 100644 src/view/com/util/Views.web.tsx (limited to 'src') diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx index a52bc643c..59dbf1e16 100644 --- a/src/view/com/post-thread/PostThread.tsx +++ b/src/view/com/post-thread/PostThread.tsx @@ -1,6 +1,7 @@ import React, {useRef} from 'react' import {observer} from 'mobx-react-lite' -import {ActivityIndicator, FlatList, View} from 'react-native' +import {ActivityIndicator, View} from 'react-native' +import {CenteredView, FlatList} from '../util/Views' import { PostThreadViewModel, PostThreadViewPostModel, @@ -50,9 +51,9 @@ export const PostThread = observer(function PostThread({ // = if ((view.isLoading && !view.isRefreshing) || view.params.uri !== uri) { return ( - + - + ) } @@ -60,9 +61,9 @@ export const PostThread = observer(function PostThread({ // = if (view.hasError) { return ( - + - + ) } diff --git a/src/view/com/posts/Feed.tsx b/src/view/com/posts/Feed.tsx index db6877660..db05caa3c 100644 --- a/src/view/com/posts/Feed.tsx +++ b/src/view/com/posts/Feed.tsx @@ -3,11 +3,11 @@ import {observer} from 'mobx-react-lite' import { ActivityIndicator, View, - FlatList, StyleProp, StyleSheet, ViewStyle, } from 'react-native' +import {CenteredView, FlatList} from '../util/Views' import {PostFeedLoadingPlaceholder} from '../util/LoadingPlaceholder' import {EmptyState} from '../util/EmptyState' import {ErrorMessage} from '../util/error/ErrorMessage' @@ -86,11 +86,16 @@ export const Feed = observer(function Feed({ ) return ( - {!data && } - {feed.isLoading && !data && } - {feed.hasError && ( - - )} + + {!data && } + {feed.isLoading && !data && } + {feed.hasError && ( + + )} + {feed.hasLoaded && data && ( for views that + * need to match layout but which aren't scrolled. + */ + +import React from 'react' +import { + FlatList as RNFlatList, + FlatListProps, + ScrollView as RNScrollView, + ScrollViewProps, + StyleSheet, + StyleProp, + View, + ViewProps, +} from 'react-native' + +export function CenteredView({ + style, + ...props +}: React.PropsWithChildren) { + style = addStyle(style, styles.container) + return +} + +export function FlatList({ + contentContainerStyle, + ...props +}: React.PropsWithChildren>) { + contentContainerStyle = addStyle(contentContainerStyle, styles.container) + return +} + +export function ScrollView({ + contentContainerStyle, + ...props +}: React.PropsWithChildren) { + contentContainerStyle = addStyle(contentContainerStyle, styles.container) + return ( + + ) +} + +function addStyle( + base: StyleProp, + addedStyle: StyleProp, +): StyleProp { + if (Array.isArray(base)) { + return base.concat([addedStyle]) + } + return [base, addedStyle] +} + +const styles = StyleSheet.create({ + container: { + width: '100%', + maxWidth: 600, + marginLeft: 'auto', + marginRight: 'auto', + }, +}) diff --git a/src/view/shell/web/index.tsx b/src/view/shell/web/index.tsx index 9032eb884..c7bfeff19 100644 --- a/src/view/shell/web/index.tsx +++ b/src/view/shell/web/index.tsx @@ -18,26 +18,22 @@ export const WebShell: React.FC = observer(() => { if (!store.session.hasSession) { return ( - - - + ) } return ( - - {screenRenderDesc.screens.map(({Com, navIdx, params, key, current}) => ( - - - - - - ))} - + {screenRenderDesc.screens.map(({Com, navIdx, params, key, current}) => ( + + + + + + ))} ) // TODO -- cgit 1.4.1