Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions example/app/(app)/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'react-native-reanimated'

import { Stack } from 'expo-router'

import { useListenLocalStorage } from '@/common/localStorage'
Expand All @@ -10,18 +8,16 @@ export default function AppLayout() {
const ready = useSplashScreen()
const [accessToken] = useListenLocalStorage('accessToken')

const isLoggedIn = Boolean(accessToken)

if (!ready) {
return <Spinner />
}

return (
<Stack screenOptions={{ headerShown: false }}>
<Stack.Protected guard={isLoggedIn}>
<Stack.Protected guard={Boolean(accessToken)}>
<Stack.Screen name="index" />
</Stack.Protected>
<Stack.Protected guard={!isLoggedIn}>
<Stack.Protected guard={!Boolean(accessToken)}>
<Stack.Screen name="login" />
</Stack.Protected>
</Stack>
Expand Down
28 changes: 11 additions & 17 deletions example/app/(app)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Line, {
} from '@xmartlabs/react-native-line'
import { useRouter } from 'expo-router'
import { Fragment, useEffect, useState } from 'react'
import { Alert, Dimensions, Image, StyleSheet } from 'react-native'
import { Alert, Dimensions, Image, StyleSheet, View } from 'react-native'

import { LineError } from '@/common/errors'
import {
Expand All @@ -15,6 +15,7 @@ import { ActivityBanner } from '@/components/ActivityBanner'
import { Bullet } from '@/components/Bullet'
import { Button } from '@/components/Button'
import { ThemedView } from '@/components/ThemedView'
import { Color } from '@/constants/color'

function handleError(error: LineError) {
const userInfo = JSON.parse(error.userInfo?.message ?? '')
Expand Down Expand Up @@ -80,17 +81,15 @@ export default function HomeScreen() {
return (
<Fragment>
<ThemedView style={styles.container}>
<ThemedView style={styles.contentContainer}>
<View style={styles.contentContainer}>
<Image source={{ uri: user?.pictureUrl }} style={styles.image} />
<Bullet header={strings.name} text={user?.displayName} />
<Bullet header={strings.userId} text={user?.userId} />
<Bullet header={strings.accessToken} text={token?.accessToken} />
</ThemedView>
<Bullet body={user?.displayName} header={strings.name} />
<Bullet body={user?.userId} header={strings.userId} />
<Bullet body={token?.accessToken} header={strings.accessToken} />
</View>
<Button onPress={verifyAccessToken} text={strings.verifyToken} />
<Button onPress={refreshAccessToken} text={strings.refreshToken} />
<Button onPress={getFriendshipStatus} text={strings.isFriend} />
<ThemedView style={styles.row}>
<Button onPress={verifyAccessToken} text={strings.verifyToken} />
<Button onPress={refreshAccessToken} text={strings.refreshToken} />
</ThemedView>
<Button onPress={logOut} text={strings.logOut} />
</ThemedView>
{loading && <ActivityBanner />}
Expand All @@ -112,7 +111,6 @@ const strings = {

const styles = StyleSheet.create({
container: {
alignItems: 'center',
flex: 1,
gap: 16,
justifyContent: 'center',
Expand All @@ -126,16 +124,12 @@ const styles = StyleSheet.create({
},
image: {
alignSelf: 'center',
backgroundColor: 'black',
borderColor: 'gray',
backgroundColor: Color.Gray,
borderColor: Color.LightGray,
borderRadius: Dimensions.get('window').width / 1.5,
borderWidth: 0.5,
height: Dimensions.get('window').width / 3,
resizeMode: 'cover',
width: Dimensions.get('window').width / 3,
},
row: {
flexDirection: 'row',
gap: 16,
},
})
9 changes: 6 additions & 3 deletions example/common/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { MMKV, useMMKVString } from 'react-native-mmkv'
import { createMMKV, useMMKVString } from 'react-native-mmkv'

const localStorage = new MMKV({ encryptionKey: 'encryptionKey', id: 'default' })
const localStorage = createMMKV({
encryptionKey: 'your-encryption-key',
id: 'default',
})

export function getLocalStorageItem(key: string) {
return localStorage.getString(key)
Expand All @@ -11,7 +14,7 @@ export function setLocalStorageItem(key: string, value: string) {
}

export function removeLocalStorageItem(key: string) {
return localStorage.delete(key)
return localStorage.remove(key)
}

export const useListenLocalStorage = (key: string) =>
Expand Down
5 changes: 3 additions & 2 deletions example/components/ActivityBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Animated, {
ZoomOut,
} from 'react-native-reanimated'

import { Color } from '@/constants/Colors'
import { Color } from '@/constants/color'

interface Props {
backgroundColor?: Color
Expand All @@ -19,7 +19,7 @@ export const ActivityBanner: FunctionComponent<Props> = ({
<Animated.View
entering={FadeIn}
exiting={FadeOut}
style={[StyleSheet.absoluteFill, styles.container, { backgroundColor }]}>
style={[styles.container, { backgroundColor }]}>
<Animated.View
entering={ZoomIn}
exiting={ZoomOut}
Expand All @@ -31,6 +31,7 @@ export const ActivityBanner: FunctionComponent<Props> = ({

const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
alignItems: 'center',
justifyContent: 'center',
},
Expand Down
23 changes: 8 additions & 15 deletions example/components/Bullet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { FunctionComponent } from 'react'
import { StyleSheet, Text } from 'react-native'
import { StyleSheet, View } from 'react-native'

import { ThemedView } from '@/components/ThemedView'
import { ThemedText } from '@/components/ThemedText'

interface Props {
body?: string
header: string
text?: string
}

export const Bullet: FunctionComponent<Props> = ({ header, text }) => (
<ThemedView style={styles.container}>
<Text style={[styles.bold, styles.text]}>{header}</Text>
<Text style={styles.text}>{text}</Text>
</ThemedView>
export const Bullet: FunctionComponent<Props> = ({ body, header }) => (
<View style={styles.container}>
<ThemedText type="subtitle">{header}</ThemedText>
<ThemedText type="default">{body}</ThemedText>
</View>
)

const styles = StyleSheet.create({
bold: {
fontWeight: 'bold',
},
container: {
gap: 4,
},
text: {
color: 'black',
fontSize: 13,
},
})
34 changes: 22 additions & 12 deletions example/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import { FunctionComponent } from 'react'
import { PressableProps, StyleSheet, Text } from 'react-native'
import { PressableProps, StyleSheet } from 'react-native'

import { PressableOpacity } from '@/components/PressableOpacity'
import { ThemedText } from '@/components/ThemedText'
import { Color } from '@/constants/color'
import { useThemeColor } from '@/hooks/useThemeColor'

interface Props extends PressableProps {
text?: string
}

export const Button: FunctionComponent<Props> = ({ onPress, text }) => (
<PressableOpacity onPress={onPress} style={styles.container}>
<Text style={styles.text}>{text}</Text>
</PressableOpacity>
)
export const Button: FunctionComponent<Props> = ({ onPress, text }) => {
const backgroundColor = useThemeColor({}, 'text')

return (
<PressableOpacity
onPress={onPress}
style={[styles.container, { backgroundColor }]}>
<ThemedText
darkColor={Color.Black}
lightColor={Color.White}
type="default">
{text}
</ThemedText>
</PressableOpacity>
)
}

const styles = StyleSheet.create({
container: {
backgroundColor: 'black',
alignItems: 'center',
borderRadius: 16,
justifyContent: 'center',
padding: 12,
},
text: {
color: 'white',
fontSize: 13,
fontWeight: 'bold',
},
})
2 changes: 1 addition & 1 deletion example/components/LineButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Image, StyleSheet, Text } from 'react-native'
import Line from '@/assets/images/line.png'
import { PressableOpacity } from '@/components/PressableOpacity'
import { VerticalDivider } from '@/components/VerticalDivider'
import { Color } from '@/constants/Colors'
import { Color } from '@/constants/color'

interface Props {
disabled?: boolean
Expand Down
2 changes: 1 addition & 1 deletion example/components/Spinner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActivityIndicator, ActivityIndicatorProps } from 'react-native'

import { Color } from '@/constants/Colors'
import { Color } from '@/constants/color'

export function Spinner(props: ActivityIndicatorProps) {
return <ActivityIndicator color={Color.Green} {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ export type ThemedTextProps = TextProps & {
}

export function ThemedText({
style,
lightColor,
darkColor,
lightColor,
style,
type = 'default',
...rest
}: ThemedTextProps) {
const color = useThemeColor({ dark: darkColor, light: lightColor }, 'text')
const link = useThemeColor({ dark: darkColor, light: lightColor }, 'link')

return (
<Text
Expand All @@ -25,7 +26,7 @@ export function ThemedText({
type === 'title' ? styles.title : undefined,
type === 'defaultSemiBold' ? styles.defaultSemiBold : undefined,
type === 'subtitle' ? styles.subtitle : undefined,
type === 'link' ? styles.link : undefined,
type === 'link' ? [styles.link, { color: link }] : undefined,
style,
]}
{...rest}
Expand All @@ -35,25 +36,24 @@ export function ThemedText({

const styles = StyleSheet.create({
default: {
fontSize: 16,
fontSize: 14,
lineHeight: 24,
},
defaultSemiBold: {
fontSize: 16,
fontSize: 14,
fontWeight: '600',
lineHeight: 24,
},
link: {
color: '#0A7EA4',
fontSize: 16,
fontSize: 14,
lineHeight: 30,
},
subtitle: {
fontSize: 20,
fontSize: 16,
fontWeight: 'bold',
},
title: {
fontSize: 24,
fontSize: 18,
fontWeight: 'bold',
lineHeight: 32,
},
Expand Down
2 changes: 1 addition & 1 deletion example/components/VerticalDivider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'

import { Color } from '@/constants/Colors'
import { Color } from '@/constants/color'

interface Props {
backgroundColor?: Color
Expand Down
9 changes: 6 additions & 3 deletions example/constants/Colors.ts → example/constants/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum Color {
Black = '#000000',
Black8PCT = '#00000014',
Black50PCT = '#00000080',
Blue = '#0A7EA4',
Gray = '#1E1E1E',
Gray20PCT = '#1E1E1E33',
Green = '#06C755',
Expand All @@ -12,15 +13,17 @@ export enum Color {

export const Colors = {
dark: {
background: Color.Gray,
background: Color.Black,
icon: Color.Green,
text: Color.LightGray,
link: Color.Green,
text: Color.White,
tint: Color.Green,
},
light: {
background: Color.White,
icon: Color.Green,
text: Color.Gray,
link: Color.Green,
text: Color.Black,
tint: Color.Green,
},
}
11 changes: 6 additions & 5 deletions example/hooks/useSplashScreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import { useEffect, useState } from 'react'
import SpaceMono from '@/assets/fonts/SpaceMono-Regular.ttf'

ExpoSplashScreen.preventAutoHideAsync()
ExpoSplashScreen.setOptions({ duration: 200, fade: true })

export const useSplashScreen = () => {
const [loaded] = useFonts({ SpaceMono })
const [ready, setReady] = useState<boolean>(false)
const [loadedSpaceMono] = useFonts({ SpaceMono })
const [ready, setReady] = useState(false)

useEffect(() => {
if (loaded) {
ExpoSplashScreen.hideAsync()
if (loadedSpaceMono) {
setReady(true)
ExpoSplashScreen.hide()
}
}, [loaded])
}, [loadedSpaceMono])

return ready
}
2 changes: 1 addition & 1 deletion example/hooks/useThemeColor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Colors } from '@/constants/Colors'
import { Colors } from '@/constants/color'
import { useColorScheme } from '@/hooks/useColorScheme'

export function useThemeColor(
Expand Down
Loading