tamagui: Popover crashes Android app. context.onOpenChange is undefined
Current Behavior
The Popover component is breaking the app on Android, throwing the following error:
It works as expected on iOS.
Expected Behavior
The Android App should not crash, and the Popover should close.
Tamagui Version
1.89.20
Platform (Web, iOS, Android)
Android
Reproduction
here is the popover implementation:
import { forwardRef } from "react";
import { Adapt, Popover, withStaticProperties } from "tamagui";
import { TransparentNavButton } from "../../form/TransparentNavButton";
import { Sheet } from "../Sheet";
import type { BaseIconProps } from "../../../helpers-icon";
import type { Ref } from "react";
import type { NamedExoticComponent } from "react";
import type {
PopoverProps,
ButtonProps as TamaguiButtonProps,
TamaguiElement,
} from "tamagui";
type ButtonProps = Omit<TamaguiButtonProps, "color" | "icon"> & {
icon: NamedExoticComponent<BaseIconProps>;
label: string;
iconProps?: BaseIconProps;
color?: string | undefined;
};
const Button = forwardRef(
(
{
icon: IconComponent,
label,
iconProps,
color = "$gray800",
onPress,
...rest
}: ButtonProps,
ref: Ref<TamaguiElement> | undefined
) => {
return (
<Popover.Close asChild="except-style">
<TransparentNavButton
icon={<IconComponent size={24} color="$gray700" {...iconProps} />}
textProps={{
col: color,
fow: "$semibold",
size: "$2",
}}
space="$3"
onPress={onPress}
ref={ref}
{...rest}
>
{label}
</TransparentNavButton>
</Popover.Close>
);
}
);
export type ActionsDropdownProps = PopoverProps & {
trigger: NamedExoticComponent<BaseIconProps>;
triggerProps?: BaseIconProps;
};
export const ActionsDropdown = withStaticProperties(
({
trigger: TriggerComponent,
triggerProps,
open,
onOpenChange,
children,
...rest
}: ActionsDropdownProps) => {
const { disabled } = triggerProps || {};
return (
<Popover
size="$5"
allowFlip
open={open}
onOpenChange={onOpenChange}
{...rest}
>
<Popover.Trigger disabled={disabled} asChild="except-style">
<TransparentNavButton
p={0}
icon={
<TriggerComponent
size={16}
color="$gray700"
disabled={disabled}
{...(disabled && { opacity: 0 })}
{...triggerProps}
/>
}
disabled={disabled}
/>
</Popover.Trigger>
<Adapt when="sm" platform="native">
<Sheet
native
modal
dismissOnSnapToBottom
animationConfig={{
type: "spring",
damping: 20,
mass: 1.2,
stiffness: 250,
}}
>
<Sheet.Body>
<Adapt.Contents />
</Sheet.Body>
</Sheet>
</Adapt>
<Popover.Content
ai="center"
jc="center"
br="$2"
p="$3"
bg="$white"
enterStyle={{ y: -10, opacity: 0 }}
exitStyle={{ y: -10, opacity: 0 }}
elevate
animation={[
"quick",
{
opacity: {
overshootClamping: true,
},
},
]}
>
<Popover.Arrow bg="$white" />
{children}
</Popover.Content>
</Popover>
);
},
{
Button,
}
);
export type ActionsDropdownButtonProps = ButtonProps;
System Info
System:
OS: macOS 14.3.1
CPU: (12) arm64 Apple M3 Pro
Memory: 881.81 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.18.2 - ~/.asdf/installs/nodejs/18.18.2/bin/node
Yarn: 1.22.21 - ~/.asdf/installs/nodejs/18.18.2/bin/yarn
npm: 9.8.1 - ~/.asdf/plugins/nodejs/shims/npm
Browsers:
Chrome: 121.0.6167.184
Safari: 17.3.1
npmPackages:
@babel/core: ^7.22.9 => 7.22.15
@techfx/eslint-config-main: 0.0.0 => 0.0.0
@techfx/prettier-config: 0.0.0 => 0.0.0
syncpack: ^12.3.0 => 12.3.0
turbo: ^1.12.3 => 1.12.3
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 15 (2 by maintainers)
I found a workaround by adding a state to control the opening and closing of the Popover, and replacing
Popover.Closewith a custom close button.I have tested this solution on tamagui versions “^1.101.7” and “^1.109.1”, but only on Android.
It works for me as well on v1.108.2 with Android. Thank you @castrosuellenx. It would be great if the fix could be incorporated directly into Tamagui.
Thanks @castrosuellenx , It’s work
Hi @byteab,
I tried reproducing the issue in a fresh app which I initialized with expo cli and later added tamagui with help of this page. The application contains a tab layout, and in the home screen there’s a ScrollView just like my app, and then I’ve simply copied the Demo from here.
Please have a look, and here’s a video of the issue as well.
Link to code: https://github.com/brokenstack/tamagui-popover-reproducible For installation and running, simply clone and install the deps then run
pnpm run localfor locally running on connected android device.https://github.com/user-attachments/assets/5c51514d-37c6-48d8-a720-edc4681cbf31
I can check that if you can a reproduction