-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: New Profile Screen (read-only) (#1519)
- Loading branch information
Showing
32 changed files
with
877 additions
and
1,052 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { memo } from "react"; | ||
import { View, ViewStyle, Switch, TouchableOpacity } from "react-native"; | ||
import { Text } from "@/design-system/Text"; | ||
import { useAppTheme, ThemedStyle } from "@/theme/useAppTheme"; | ||
import { HStack } from "@/design-system/HStack"; | ||
import { VStack } from "@/design-system/VStack"; | ||
import { Icon } from "@/design-system/Icon/Icon"; | ||
import { ISettingsListRow } from "./settings-list.types"; | ||
|
||
type ISettingsListRowProps = { | ||
row: ISettingsListRow; | ||
editMode?: boolean; | ||
}; | ||
|
||
export const SettingsListRow = memo(function SettingsListRow({ | ||
row, | ||
editMode, | ||
}: ISettingsListRowProps) { | ||
const { theme, themed } = useAppTheme(); | ||
|
||
const content = ( | ||
<HStack style={themed($innerRowContainer)}> | ||
<VStack style={{ flex: 1 }}> | ||
<Text color={row.isWarning ? "caution" : "primary"}>{row.label}</Text> | ||
{row.value && ( | ||
<Text | ||
preset="formLabel" | ||
color={row.isWarning ? "caution" : "secondary"} | ||
> | ||
{row.value} | ||
</Text> | ||
)} | ||
</VStack> | ||
<View style={themed($rightContentContainer)}> | ||
{row.isSwitch ? ( | ||
<Switch | ||
value={!!row.value} | ||
onValueChange={row.onValueChange} | ||
disabled={row.disabled} | ||
/> | ||
) : ( | ||
<Icon | ||
icon="chevron.right" | ||
size={theme.iconSize.sm} | ||
color={theme.colors.text.secondary} | ||
/> | ||
)} | ||
</View> | ||
</HStack> | ||
); | ||
|
||
if (row.onPress) { | ||
return ( | ||
<TouchableOpacity style={themed($rowContainer)} onPress={row.onPress}> | ||
{content} | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
return <HStack style={themed($rowContainer)}>{content}</HStack>; | ||
}); | ||
|
||
const $rowContainer: ThemedStyle<ViewStyle> = ({ spacing }) => ({ | ||
paddingVertical: spacing.md, | ||
width: "100%", | ||
flexDirection: "row", | ||
alignItems: "center", | ||
}); | ||
|
||
const $innerRowContainer: ThemedStyle<ViewStyle> = () => ({ | ||
width: "100%", | ||
justifyContent: "space-between", | ||
alignItems: "center", | ||
}); | ||
|
||
const $rightContentContainer: ThemedStyle<ViewStyle> = () => ({ | ||
marginLeft: "auto", | ||
alignItems: "flex-end", | ||
justifyContent: "center", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { memo } from "react"; | ||
import { View, ViewStyle } from "react-native"; | ||
import { useAppTheme, ThemedStyle } from "@/theme/useAppTheme"; | ||
import { SettingsListRow } from "./settings-list-row"; | ||
import { ISettingsListRow } from "./settings-list.types"; | ||
|
||
type ISettingsListProps = { | ||
rows: ISettingsListRow[]; | ||
editMode?: boolean; | ||
}; | ||
|
||
export const SettingsList = memo(function SettingsList({ | ||
rows, | ||
editMode, | ||
}: ISettingsListProps) { | ||
const { themed } = useAppTheme(); | ||
|
||
return ( | ||
<View style={themed($container)}> | ||
{rows.map((row, index) => ( | ||
<SettingsListRow | ||
key={row.label + index} | ||
row={row} | ||
editMode={editMode} | ||
/> | ||
))} | ||
</View> | ||
); | ||
}); | ||
|
||
const $container: ThemedStyle<ViewStyle> = () => ({ | ||
width: "100%", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type ISettingsListRow = { | ||
label: string; | ||
value?: string | boolean; | ||
onPress?: () => void; | ||
onValueChange?: (value: boolean) => void; | ||
isWarning?: boolean; | ||
isSwitch?: boolean; | ||
disabled?: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
features/notifications/hooks/use-notifications-permission.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Platform, Linking } from "react-native"; | ||
import { useAppStore } from "@/data/store/appStore"; | ||
import { requestPushNotificationsPermissions } from "../utils/requestPushNotificationsPermissions"; | ||
import { useSettingsStore } from "@/data/store/accountsStore"; | ||
|
||
type UseNotificationsPermissionReturn = { | ||
notificationsPermissionStatus: "granted" | "undetermined" | "denied"; | ||
requestPermission: () => Promise<void>; | ||
setNotificationsSettings: (settings: { | ||
showNotificationScreen: boolean; | ||
}) => void; | ||
}; | ||
|
||
export function useNotificationsPermission(): UseNotificationsPermissionReturn { | ||
const notificationsPermissionStatus = useAppStore( | ||
(s) => s.notificationsPermissionStatus | ||
); | ||
const setNotificationsPermissionStatus = useAppStore( | ||
(s) => s.setNotificationsPermissionStatus | ||
); | ||
const setNotificationsSettings = useSettingsStore( | ||
(s) => s.setNotificationsSettings | ||
); | ||
|
||
const requestPermission = async () => { | ||
if (notificationsPermissionStatus === "denied") { | ||
if (Platform.OS === "android") { | ||
// Android 13 is always denied first so let's try to show | ||
const newStatus = await requestPushNotificationsPermissions(); | ||
if (newStatus === "denied") { | ||
Linking.openSettings(); | ||
} else if (newStatus) { | ||
setNotificationsPermissionStatus(newStatus); | ||
} | ||
} else { | ||
Linking.openSettings(); | ||
} | ||
} else if (notificationsPermissionStatus === "undetermined") { | ||
// Open popup | ||
const newStatus = await requestPushNotificationsPermissions(); | ||
if (!newStatus) return; | ||
setNotificationsPermissionStatus(newStatus); | ||
} | ||
}; | ||
|
||
return { | ||
notificationsPermissionStatus, | ||
requestPermission, | ||
setNotificationsSettings, | ||
}; | ||
} |
Oops, something went wrong.