Skip to content

Commit ab0283f

Browse files
authored
Merge pull request #210 from xmartlabs/mmkv
[Chore] Upgrade MMKV
2 parents 2fc1c52 + a4b45bb commit ab0283f

16 files changed

Lines changed: 95 additions & 82 deletions

File tree

example/app/(app)/_layout.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'react-native-reanimated'
2-
31
import { Stack } from 'expo-router'
42

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

13-
const isLoggedIn = Boolean(accessToken)
14-
1511
if (!ready) {
1612
return <Spinner />
1713
}
1814

1915
return (
2016
<Stack screenOptions={{ headerShown: false }}>
21-
<Stack.Protected guard={isLoggedIn}>
17+
<Stack.Protected guard={Boolean(accessToken)}>
2218
<Stack.Screen name="index" />
2319
</Stack.Protected>
24-
<Stack.Protected guard={!isLoggedIn}>
20+
<Stack.Protected guard={!Boolean(accessToken)}>
2521
<Stack.Screen name="login" />
2622
</Stack.Protected>
2723
</Stack>

example/app/(app)/index.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Line, {
44
} from '@xmartlabs/react-native-line'
55
import { useRouter } from 'expo-router'
66
import { Fragment, useEffect, useState } from 'react'
7-
import { Alert, Dimensions, Image, StyleSheet } from 'react-native'
7+
import { Alert, Dimensions, Image, StyleSheet, View } from 'react-native'
88

99
import { LineError } from '@/common/errors'
1010
import {
@@ -15,6 +15,7 @@ import { ActivityBanner } from '@/components/ActivityBanner'
1515
import { Bullet } from '@/components/Bullet'
1616
import { Button } from '@/components/Button'
1717
import { ThemedView } from '@/components/ThemedView'
18+
import { Color } from '@/constants/color'
1819

1920
function handleError(error: LineError) {
2021
const userInfo = JSON.parse(error.userInfo?.message ?? '')
@@ -80,17 +81,15 @@ export default function HomeScreen() {
8081
return (
8182
<Fragment>
8283
<ThemedView style={styles.container}>
83-
<ThemedView style={styles.contentContainer}>
84+
<View style={styles.contentContainer}>
8485
<Image source={{ uri: user?.pictureUrl }} style={styles.image} />
85-
<Bullet header={strings.name} text={user?.displayName} />
86-
<Bullet header={strings.userId} text={user?.userId} />
87-
<Bullet header={strings.accessToken} text={token?.accessToken} />
88-
</ThemedView>
86+
<Bullet body={user?.displayName} header={strings.name} />
87+
<Bullet body={user?.userId} header={strings.userId} />
88+
<Bullet body={token?.accessToken} header={strings.accessToken} />
89+
</View>
90+
<Button onPress={verifyAccessToken} text={strings.verifyToken} />
91+
<Button onPress={refreshAccessToken} text={strings.refreshToken} />
8992
<Button onPress={getFriendshipStatus} text={strings.isFriend} />
90-
<ThemedView style={styles.row}>
91-
<Button onPress={verifyAccessToken} text={strings.verifyToken} />
92-
<Button onPress={refreshAccessToken} text={strings.refreshToken} />
93-
</ThemedView>
9493
<Button onPress={logOut} text={strings.logOut} />
9594
</ThemedView>
9695
{loading && <ActivityBanner />}
@@ -112,7 +111,6 @@ const strings = {
112111

113112
const styles = StyleSheet.create({
114113
container: {
115-
alignItems: 'center',
116114
flex: 1,
117115
gap: 16,
118116
justifyContent: 'center',
@@ -126,16 +124,12 @@ const styles = StyleSheet.create({
126124
},
127125
image: {
128126
alignSelf: 'center',
129-
backgroundColor: 'black',
130-
borderColor: 'gray',
127+
backgroundColor: Color.Gray,
128+
borderColor: Color.LightGray,
131129
borderRadius: Dimensions.get('window').width / 1.5,
132130
borderWidth: 0.5,
133131
height: Dimensions.get('window').width / 3,
134132
resizeMode: 'cover',
135133
width: Dimensions.get('window').width / 3,
136134
},
137-
row: {
138-
flexDirection: 'row',
139-
gap: 16,
140-
},
141135
})

example/common/localStorage.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
import { MMKV, useMMKVString } from 'react-native-mmkv'
1+
import { createMMKV, useMMKVString } from 'react-native-mmkv'
22

3-
const localStorage = new MMKV({ encryptionKey: 'encryptionKey', id: 'default' })
3+
const localStorage = createMMKV({
4+
encryptionKey: 'your-encryption-key',
5+
id: 'default',
6+
})
47

58
export function getLocalStorageItem(key: string) {
69
return localStorage.getString(key)
@@ -11,7 +14,7 @@ export function setLocalStorageItem(key: string, value: string) {
1114
}
1215

1316
export function removeLocalStorageItem(key: string) {
14-
return localStorage.delete(key)
17+
return localStorage.remove(key)
1518
}
1619

1720
export const useListenLocalStorage = (key: string) =>

example/components/ActivityBanner/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Animated, {
77
ZoomOut,
88
} from 'react-native-reanimated'
99

10-
import { Color } from '@/constants/Colors'
10+
import { Color } from '@/constants/color'
1111

1212
interface Props {
1313
backgroundColor?: Color
@@ -19,7 +19,7 @@ export const ActivityBanner: FunctionComponent<Props> = ({
1919
<Animated.View
2020
entering={FadeIn}
2121
exiting={FadeOut}
22-
style={[StyleSheet.absoluteFill, styles.container, { backgroundColor }]}>
22+
style={[styles.container, { backgroundColor }]}>
2323
<Animated.View
2424
entering={ZoomIn}
2525
exiting={ZoomOut}
@@ -31,6 +31,7 @@ export const ActivityBanner: FunctionComponent<Props> = ({
3131

3232
const styles = StyleSheet.create({
3333
container: {
34+
...StyleSheet.absoluteFillObject,
3435
alignItems: 'center',
3536
justifyContent: 'center',
3637
},
Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
import { FunctionComponent } from 'react'
2-
import { StyleSheet, Text } from 'react-native'
2+
import { StyleSheet, View } from 'react-native'
33

4-
import { ThemedView } from '@/components/ThemedView'
4+
import { ThemedText } from '@/components/ThemedText'
55

66
interface Props {
7+
body?: string
78
header: string
8-
text?: string
99
}
1010

11-
export const Bullet: FunctionComponent<Props> = ({ header, text }) => (
12-
<ThemedView style={styles.container}>
13-
<Text style={[styles.bold, styles.text]}>{header}</Text>
14-
<Text style={styles.text}>{text}</Text>
15-
</ThemedView>
11+
export const Bullet: FunctionComponent<Props> = ({ body, header }) => (
12+
<View style={styles.container}>
13+
<ThemedText type="subtitle">{header}</ThemedText>
14+
<ThemedText type="default">{body}</ThemedText>
15+
</View>
1616
)
1717

1818
const styles = StyleSheet.create({
19-
bold: {
20-
fontWeight: 'bold',
21-
},
2219
container: {
2320
gap: 4,
2421
},
25-
text: {
26-
color: 'black',
27-
fontSize: 13,
28-
},
2922
})
Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import { FunctionComponent } from 'react'
2-
import { PressableProps, StyleSheet, Text } from 'react-native'
2+
import { PressableProps, StyleSheet } from 'react-native'
33

44
import { PressableOpacity } from '@/components/PressableOpacity'
5+
import { ThemedText } from '@/components/ThemedText'
6+
import { Color } from '@/constants/color'
7+
import { useThemeColor } from '@/hooks/useThemeColor'
58

69
interface Props extends PressableProps {
710
text?: string
811
}
912

10-
export const Button: FunctionComponent<Props> = ({ onPress, text }) => (
11-
<PressableOpacity onPress={onPress} style={styles.container}>
12-
<Text style={styles.text}>{text}</Text>
13-
</PressableOpacity>
14-
)
13+
export const Button: FunctionComponent<Props> = ({ onPress, text }) => {
14+
const backgroundColor = useThemeColor({}, 'text')
15+
16+
return (
17+
<PressableOpacity
18+
onPress={onPress}
19+
style={[styles.container, { backgroundColor }]}>
20+
<ThemedText
21+
darkColor={Color.Black}
22+
lightColor={Color.White}
23+
type="default">
24+
{text}
25+
</ThemedText>
26+
</PressableOpacity>
27+
)
28+
}
1529

1630
const styles = StyleSheet.create({
1731
container: {
18-
backgroundColor: 'black',
32+
alignItems: 'center',
1933
borderRadius: 16,
34+
justifyContent: 'center',
2035
padding: 12,
2136
},
22-
text: {
23-
color: 'white',
24-
fontSize: 13,
25-
fontWeight: 'bold',
26-
},
2737
})

example/components/LineButton/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Image, StyleSheet, Text } from 'react-native'
44
import Line from '@/assets/images/line.png'
55
import { PressableOpacity } from '@/components/PressableOpacity'
66
import { VerticalDivider } from '@/components/VerticalDivider'
7-
import { Color } from '@/constants/Colors'
7+
import { Color } from '@/constants/color'
88

99
interface Props {
1010
disabled?: boolean

example/components/Spinner/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ActivityIndicator, ActivityIndicatorProps } from 'react-native'
22

3-
import { Color } from '@/constants/Colors'
3+
import { Color } from '@/constants/color'
44

55
export function Spinner(props: ActivityIndicatorProps) {
66
return <ActivityIndicator color={Color.Green} {...props} />
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ export type ThemedTextProps = TextProps & {
99
}
1010

1111
export function ThemedText({
12-
style,
13-
lightColor,
1412
darkColor,
13+
lightColor,
14+
style,
1515
type = 'default',
1616
...rest
1717
}: ThemedTextProps) {
1818
const color = useThemeColor({ dark: darkColor, light: lightColor }, 'text')
19+
const link = useThemeColor({ dark: darkColor, light: lightColor }, 'link')
1920

2021
return (
2122
<Text
@@ -25,7 +26,7 @@ export function ThemedText({
2526
type === 'title' ? styles.title : undefined,
2627
type === 'defaultSemiBold' ? styles.defaultSemiBold : undefined,
2728
type === 'subtitle' ? styles.subtitle : undefined,
28-
type === 'link' ? styles.link : undefined,
29+
type === 'link' ? [styles.link, { color: link }] : undefined,
2930
style,
3031
]}
3132
{...rest}
@@ -35,25 +36,24 @@ export function ThemedText({
3536

3637
const styles = StyleSheet.create({
3738
default: {
38-
fontSize: 16,
39+
fontSize: 14,
3940
lineHeight: 24,
4041
},
4142
defaultSemiBold: {
42-
fontSize: 16,
43+
fontSize: 14,
4344
fontWeight: '600',
4445
lineHeight: 24,
4546
},
4647
link: {
47-
color: '#0A7EA4',
48-
fontSize: 16,
48+
fontSize: 14,
4949
lineHeight: 30,
5050
},
5151
subtitle: {
52-
fontSize: 20,
52+
fontSize: 16,
5353
fontWeight: 'bold',
5454
},
5555
title: {
56-
fontSize: 24,
56+
fontSize: 18,
5757
fontWeight: 'bold',
5858
lineHeight: 32,
5959
},

0 commit comments

Comments
 (0)