-
Notifications
You must be signed in to change notification settings - Fork 928
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rn-base): split some ui components
Signed-off-by: Innei <tukon479@gmail.com>
- Loading branch information
Showing
17 changed files
with
203 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { StyleSheet } from "react-native" | ||
import { useColor } from "react-native-uikit-colors" | ||
|
||
import { ThemedBlurView } from "@/src/components/common/ThemedBlurView" | ||
|
||
const node = ( | ||
<ThemedBlurView | ||
style={{ | ||
...StyleSheet.absoluteFillObject, | ||
overflow: "hidden", | ||
backgroundColor: "transparent", | ||
}} | ||
/> | ||
) | ||
export const BlurEffect = () => { | ||
return node | ||
} | ||
|
||
const InternalBlurEffectWithBottomBorder = () => { | ||
const border = useColor("opaqueSeparator") | ||
return ( | ||
<ThemedBlurView | ||
style={{ | ||
...StyleSheet.absoluteFillObject, | ||
overflow: "hidden", | ||
backgroundColor: "transparent", | ||
borderBottomWidth: StyleSheet.hairlineWidth, | ||
borderBottomColor: border, | ||
}} | ||
/> | ||
) | ||
} | ||
|
||
export const BlurEffectWithBottomBorder = () => <InternalBlurEffectWithBottomBorder /> |
This file was deleted.
Oops, something went wrong.
63 changes: 54 additions & 9 deletions
63
apps/mobile/src/components/common/SafeNavigationScrollView.tsx
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 |
---|---|---|
@@ -1,20 +1,65 @@ | ||
import { useBottomTabBarHeight } from "@react-navigation/bottom-tabs" | ||
import { useHeaderHeight } from "@react-navigation/elements" | ||
import { router, Stack, useNavigation } from "expo-router" | ||
import type { FC } from "react" | ||
import type { ScrollViewProps } from "react-native" | ||
import { ScrollView, View } from "react-native" | ||
import { ScrollView, TouchableOpacity, View } from "react-native" | ||
import { useSafeAreaInsets } from "react-native-safe-area-context" | ||
import { useColor } from "react-native-uikit-colors" | ||
|
||
export const SafeNavigationScrollView: FC<ScrollViewProps> = ({ children, ...props }) => { | ||
const headerHeight = useHeaderHeight() | ||
const tabBarHeight = useBottomTabBarHeight() | ||
import { MingcuteLeftLineIcon } from "@/src/icons/mingcute_left_line" | ||
|
||
import { BlurEffectWithBottomBorder } from "./BlurEffect" | ||
|
||
type SafeNavigationScrollViewProps = ScrollViewProps & { | ||
withHeaderBlur?: boolean | ||
} | ||
|
||
export const SafeNavigationScrollView: FC<SafeNavigationScrollViewProps> = ({ | ||
children, | ||
|
||
withHeaderBlur = true, | ||
...props | ||
}) => { | ||
const insets = useSafeAreaInsets() | ||
const tabBarHeight = useBottomTabBarHeight() | ||
const headerHeight = useHeaderHeight() | ||
|
||
return ( | ||
<ScrollView contentInsetAdjustmentBehavior="automatic" {...props}> | ||
<View style={{ height: headerHeight - insets.top }} /> | ||
<View>{children}</View> | ||
<View style={{ height: tabBarHeight - insets.bottom }} /> | ||
</ScrollView> | ||
<> | ||
{withHeaderBlur && <NavigationBlurEffectHeader />} | ||
<ScrollView contentInsetAdjustmentBehavior="automatic" {...props}> | ||
<View style={{ height: headerHeight - insets.top }} /> | ||
<View>{children}</View> | ||
<View style={{ height: tabBarHeight - insets.bottom }} /> | ||
</ScrollView> | ||
</> | ||
) | ||
} | ||
|
||
export interface NavigationBlurEffectHeaderProps { | ||
title?: string | ||
} | ||
export const NavigationBlurEffectHeader = (props: NavigationBlurEffectHeaderProps) => { | ||
const label = useColor("label") | ||
|
||
const canBack = useNavigation().canGoBack() | ||
|
||
return ( | ||
<Stack.Screen | ||
options={{ | ||
headerBackground: BlurEffectWithBottomBorder, | ||
headerTransparent: true, | ||
|
||
headerLeft: canBack | ||
? () => ( | ||
<TouchableOpacity hitSlop={10} onPress={() => router.back()}> | ||
<MingcuteLeftLineIcon height={20} width={20} color={label} /> | ||
</TouchableOpacity> | ||
) | ||
: undefined, | ||
title: props.title, | ||
}} | ||
/> | ||
) | ||
} |
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,52 @@ | ||
import type { NativeSyntheticEvent } from "react-native" | ||
import type { ContextMenuOnPressNativeEvent } from "react-native-context-menu-view" | ||
import ContextMenu from "react-native-context-menu-view" | ||
|
||
interface DropdownMenuAction<T> { | ||
title: string | ||
actions?: DropdownMenuAction<T>[] | ||
selected?: boolean | ||
} | ||
|
||
interface DropdownMenuSelector<T> { | ||
label: string | ||
value: T | ||
} | ||
|
||
export function DropdownMenu<T>({ | ||
options, | ||
currentValue, | ||
handleChangeValue, | ||
handlePress, | ||
children, | ||
}: { | ||
options: DropdownMenuSelector<T>[] | DropdownMenuAction<T>[] | ||
currentValue?: T | ||
handleChangeValue?: (value: T) => void | ||
handlePress?: (e: NativeSyntheticEvent<ContextMenuOnPressNativeEvent>) => void | ||
children: React.ReactNode | ||
}) { | ||
const isActionMenu = options.every((option) => "title" in option) | ||
return ( | ||
<ContextMenu | ||
dropdownMenuMode | ||
actions={ | ||
isActionMenu | ||
? options | ||
: options.map((option) => ({ | ||
title: option.label, | ||
selected: option.value === currentValue, | ||
})) | ||
} | ||
onPress={(e) => { | ||
if (!isActionMenu) { | ||
const { index } = e.nativeEvent | ||
handleChangeValue?.(options[index]!.value) | ||
} | ||
handlePress?.(e) | ||
}} | ||
> | ||
{children} | ||
</ContextMenu> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,13 +1,26 @@ | ||
import { ScrollView } from "react-native" | ||
import { router } from "expo-router" | ||
|
||
import { GroupedInsetListCard, GroupedInsetListItem } from "@/src/components/ui/grouped/GroupedList" | ||
import { | ||
NavigationBlurEffectHeader, | ||
SafeNavigationScrollView, | ||
} from "@/src/components/common/SafeNavigationScrollView" | ||
import { | ||
GroupedInsetListCard, | ||
GroupedInsetListNavigationLink, | ||
} from "@/src/components/ui/grouped/GroupedList" | ||
|
||
export const PrivacyScreen = () => { | ||
return ( | ||
<ScrollView> | ||
<SafeNavigationScrollView className="bg-system-grouped-background"> | ||
<NavigationBlurEffectHeader title="Privacy" /> | ||
<GroupedInsetListCard> | ||
<GroupedInsetListItem /> | ||
<GroupedInsetListNavigationLink | ||
label="Teams" | ||
onPress={() => { | ||
router.push("/teams") | ||
}} | ||
/> | ||
</GroupedInsetListCard> | ||
</ScrollView> | ||
</SafeNavigationScrollView> | ||
) | ||
} |
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
Oops, something went wrong.