diff options
Diffstat (limited to 'app/components/screen')
-rw-r--r-- | app/components/screen/screen.presets.ts | 20 | ||||
-rw-r--r-- | app/components/screen/screen.props.ts | 10 | ||||
-rw-r--r-- | app/components/screen/screen.tsx | 42 |
3 files changed, 42 insertions, 30 deletions
diff --git a/app/components/screen/screen.presets.ts b/app/components/screen/screen.presets.ts index a016b77..aa8d8cf 100644 --- a/app/components/screen/screen.presets.ts +++ b/app/components/screen/screen.presets.ts @@ -1,5 +1,5 @@ -import { ViewStyle } from "react-native" -import { color } from "../../theme" +import { ViewStyle } from 'react-native' +import { color } from '../../theme' /** * All screen keyboard offsets. @@ -25,13 +25,13 @@ export const presets = { outer: { backgroundColor: color.background, flex: 1, - height: "100%", + height: '100%', } as ViewStyle, inner: { - justifyContent: "flex-start", - alignItems: "stretch", - height: "100%", - width: "100%", + justifyContent: 'flex-start', + alignItems: 'stretch', + height: '100%', + width: '100%', } as ViewStyle, }, @@ -44,9 +44,9 @@ export const presets = { outer: { backgroundColor: color.background, flex: 1, - height: "100%", + height: '100%', } as ViewStyle, - inner: { justifyContent: "flex-start", alignItems: "stretch" } as ViewStyle, + inner: { justifyContent: 'flex-start', alignItems: 'stretch' } as ViewStyle, }, } @@ -62,5 +62,5 @@ export type ScreenPresets = keyof typeof presets */ export function isNonScrolling(preset?: ScreenPresets) { // any of these things will make you scroll - return !preset || !presets[preset] || preset === "fixed" + return !preset || !presets[preset] || preset === 'fixed' } diff --git a/app/components/screen/screen.props.ts b/app/components/screen/screen.props.ts index 0326fd7..1371c64 100644 --- a/app/components/screen/screen.props.ts +++ b/app/components/screen/screen.props.ts @@ -1,6 +1,6 @@ -import React from "react" -import { StyleProp, ViewStyle } from "react-native" -import { KeyboardOffsets, ScreenPresets } from "./screen.presets" +import React from 'react' +import { StyleProp, ViewStyle } from 'react-native' +import { KeyboardOffsets, ScreenPresets } from './screen.presets' export interface ScreenProps { /** @@ -26,7 +26,7 @@ export interface ScreenProps { /** * An optional status bar setting. Defaults to light-content. */ - statusBar?: "light-content" | "dark-content" + statusBar?: 'light-content' | 'dark-content' /** * Should we not wrap in SafeAreaView? Defaults to false. @@ -42,5 +42,5 @@ export interface ScreenProps { * Should keyboard persist on screen tap. Defaults to handled. * Only applies to scroll preset. */ - keyboardShouldPersistTaps?: "handled" | "always" | "never" + keyboardShouldPersistTaps?: 'handled' | 'always' | 'never' } diff --git a/app/components/screen/screen.tsx b/app/components/screen/screen.tsx index ba84547..e593dde 100644 --- a/app/components/screen/screen.tsx +++ b/app/components/screen/screen.tsx @@ -1,25 +1,33 @@ -import * as React from "react" -import { KeyboardAvoidingView, Platform, ScrollView, StatusBar, View } from "react-native" -import { useSafeAreaInsets } from "react-native-safe-area-context" -import { ScreenProps } from "./screen.props" -import { isNonScrolling, offsets, presets } from "./screen.presets" +import * as React from 'react' +import { + KeyboardAvoidingView, + Platform, + ScrollView, + StatusBar, + View, +} from 'react-native' +import { useSafeAreaInsets } from 'react-native-safe-area-context' +import { ScreenProps } from './screen.props' +import { isNonScrolling, offsets, presets } from './screen.presets' -const isIos = Platform.OS === "ios" +const isIos = Platform.OS === 'ios' function ScreenWithoutScrolling(props: ScreenProps) { const insets = useSafeAreaInsets() const preset = presets.fixed const style = props.style || {} - const backgroundStyle = props.backgroundColor ? { backgroundColor: props.backgroundColor } : {} + const backgroundStyle = props.backgroundColor + ? { backgroundColor: props.backgroundColor } + : {} const insetStyle = { paddingTop: props.unsafe ? 0 : insets.top } return ( <KeyboardAvoidingView style={[preset.outer, backgroundStyle]} - behavior={isIos ? "padding" : undefined} - keyboardVerticalOffset={offsets[props.keyboardOffset || "none"]} + behavior={isIos ? 'padding' : undefined} + keyboardVerticalOffset={offsets[props.keyboardOffset || 'none']} > - <StatusBar barStyle={props.statusBar || "light-content"} /> + <StatusBar barStyle={props.statusBar || 'light-content'} /> <View style={[preset.inner, style, insetStyle]}>{props.children}</View> </KeyboardAvoidingView> ) @@ -29,21 +37,25 @@ function ScreenWithScrolling(props: ScreenProps) { const insets = useSafeAreaInsets() const preset = presets.scroll const style = props.style || {} - const backgroundStyle = props.backgroundColor ? { backgroundColor: props.backgroundColor } : {} + const backgroundStyle = props.backgroundColor + ? { backgroundColor: props.backgroundColor } + : {} const insetStyle = { paddingTop: props.unsafe ? 0 : insets.top } return ( <KeyboardAvoidingView style={[preset.outer, backgroundStyle]} - behavior={isIos ? "padding" : undefined} - keyboardVerticalOffset={offsets[props.keyboardOffset || "none"]} + behavior={isIos ? 'padding' : undefined} + keyboardVerticalOffset={offsets[props.keyboardOffset || 'none']} > - <StatusBar barStyle={props.statusBar || "light-content"} /> + <StatusBar barStyle={props.statusBar || 'light-content'} /> <View style={[preset.outer, backgroundStyle, insetStyle]}> <ScrollView style={[preset.outer, backgroundStyle]} contentContainerStyle={[preset.inner, style]} - keyboardShouldPersistTaps={props.keyboardShouldPersistTaps || "handled"} + keyboardShouldPersistTaps={ + props.keyboardShouldPersistTaps || 'handled' + } > {props.children} </ScrollView> |