feat: implement imperative modal (#4041)

* feat: implement ImperativeModalProvider with modal context and controls

* fix: make onClose prop optional for bottom modal

* chore: add ImperativeModalProvider to context providers

* feat: wrap BottomModal content in KeyboardAvoidingView for better keyboard handling

* chore: add polyfill for Promise.withResolvers

* fix: wrap ImperativeModal in a View and update onClose to accept modal ID

* feat: implement ImperativeModal with context and modal control hooks

* refactor: redesign imperative modal with root-siblings

* fix: wrap BottomModal in a View to resolve rendering issues on Android

* refactor: replace Alert.prompt with modalPrompt for category creation and renaming
This commit is contained in:
Whitewater
2025-07-02 17:20:41 +00:00
committed by GitHub
parent e91b2bfa6a
commit e9e67de25f
9 changed files with 352 additions and 64 deletions
+21 -24
View File
@@ -201,31 +201,28 @@ const SelectableTextSheet: FC<{
}
return (
// Wrap in a View to avoid rendering issues with Modal on Android
<View>
<BottomModal visible={visible} onClose={onClose}>
<View className="p-4" style={{ paddingBottom: insets.bottom + 10 }}>
<View className="mb-4 flex-row items-center justify-between">
<TouchableOpacity
onPress={handleCopyAll}
className="rounded-full bg-zinc-100 p-2 active:opacity-80 dark:bg-zinc-800"
>
<CopyCuteReIcon width={18} height={18} color={textColor} />
</TouchableOpacity>
<Text className="text-label text-lg font-semibold">AI Summary</Text>
<TouchableOpacity
onPress={onClose}
className="rounded-full bg-zinc-100 p-2 active:opacity-80 dark:bg-zinc-800"
>
<CloseCuteReIcon width={18} height={18} color={textColor} />
</TouchableOpacity>
</View>
<ScrollView showsVerticalScrollIndicator={false}>
<SelectableText className="text-label text-base leading-6">{text}</SelectableText>
</ScrollView>
<BottomModal visible={visible} onClose={onClose}>
<View className="p-4" style={{ paddingBottom: insets.bottom + 10 }}>
<View className="mb-4 flex-row items-center justify-between">
<TouchableOpacity
onPress={handleCopyAll}
className="rounded-full bg-zinc-100 p-2 active:opacity-80 dark:bg-zinc-800"
>
<CopyCuteReIcon width={18} height={18} color={textColor} />
</TouchableOpacity>
<Text className="text-label text-lg font-semibold">AI Summary</Text>
<TouchableOpacity
onPress={onClose}
className="rounded-full bg-zinc-100 p-2 active:opacity-80 dark:bg-zinc-800"
>
<CloseCuteReIcon width={18} height={18} color={textColor} />
</TouchableOpacity>
</View>
</BottomModal>
</View>
<ScrollView showsVerticalScrollIndicator={false}>
<SelectableText className="text-label text-base leading-6">{text}</SelectableText>
</ScrollView>
</View>
</BottomModal>
)
}
+20 -10
View File
@@ -17,9 +17,11 @@ import { Alert, FlatList, View } from "react-native"
import { useFetchEntriesSettings } from "@/src/atoms/settings/general"
import { ContextMenu } from "@/src/components/ui/context-menu"
import { PlatformActivityIndicator } from "@/src/components/ui/loading/PlatformActivityIndicator"
import { modalPrompt } from "@/src/components/ui/modal/imperative-modal"
import { views } from "@/src/constants/views"
import { useNavigation } from "@/src/lib/navigation/hooks"
import type { Navigation } from "@/src/lib/navigation/Navigation"
import { isIOS } from "@/src/lib/platform"
import { toast } from "@/src/lib/toast"
import { FollowScreen } from "@/src/screens/(modal)/FollowScreen"
import { FeedScreen } from "@/src/screens/(stack)/feeds/[feedId]/FeedScreen"
@@ -158,7 +160,9 @@ const generateSubscriptionContextMenu = (navigation: Navigation, id: string) =>
// create new category
const subscription = getSubscriptionById(id)
if (!subscription) return
Alert.prompt("Create New Category", "Enter the name of the new category", (text) => {
const prompt = isIOS ? Alert.prompt : modalPrompt
prompt("Create New Category", "Enter the name of the new category", (text) => {
subscriptionSyncService.edit({
...subscription,
category: text,
@@ -327,19 +331,25 @@ export const SubscriptionFeedCategoryContextMenu = ({
<ContextMenu.Item
key="EditCategory"
onSelect={() => {
Alert.prompt(
const prompt = isIOS ? Alert.prompt : modalPrompt
const handleRenameCategory = async (newCategory: string) => {
if (!newCategory) return
await subscriptionSyncService.renameCategory({
lastCategory: category,
newCategory,
view: currentView,
})
toast.success("Category renamed successfully")
}
prompt(
t("operation.rename_category"),
t("operation.enter_new_name_for_category", {
category,
}),
(newCategory) => {
if (!newCategory) return
subscriptionSyncService.renameCategory({
lastCategory: category,
newCategory,
view: currentView,
})
},
handleRenameCategory,
undefined,
category,
)
}}
>