forked from vendetta-mod/Vendetta
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): ponyfill AlertModal's
extraContent
prop for older versions
supersedes vendetta-mod#91
- Loading branch information
Showing
3 changed files
with
48 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { lazyDestructure } from "@lib/utils/lazy"; | ||
import { findByProps } from "@metro"; | ||
import { Text } from "@metro/common/components"; | ||
import { Button } from "@metro/common/types/components"; | ||
import { ComponentProps, ComponentType, ReactNode } from "react"; | ||
import { useWindowDimensions, View } from "react-native"; | ||
|
||
const { | ||
AlertModal: _AlertModal, | ||
AlertActionButton: _AlertActionButton | ||
} = lazyDestructure(() => findByProps("AlertModal", "AlertActions")); | ||
|
||
type ActionButtonProps = Omit<ComponentProps<Button>, "onPress"> & { | ||
onPress?: () => void | Promise<unknown>; | ||
}; | ||
|
||
export const AlertActionButton = _AlertActionButton as ComponentType<ActionButtonProps>; | ||
|
||
export default function AlertModal(props: Record<string, unknown>) { | ||
const { width: windowWidth } = useWindowDimensions(); | ||
|
||
// ponyfill for extraContent | ||
if ("extraContent" in props) { | ||
props.content = ( | ||
<View | ||
style={{ | ||
/* HACK: the contents are drawn over the padding for some reason, so we set the max width */ | ||
maxWidth: windowWidth - 70, | ||
flexShrink: 1, // has no effect but we'll keep it | ||
gap: 16 | ||
}}> | ||
<Text variant="text-md/medium" color="text-muted"> | ||
{props.content as string} | ||
</Text> | ||
<View> | ||
{props.extraContent as ReactNode} | ||
</View> | ||
</View> | ||
); | ||
|
||
delete props.extraContent; | ||
} | ||
|
||
return <_AlertModal {...props} />; | ||
} |
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