Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image picker is immediately closed after dismissing the action sheeting #3077

Open
2 of 7 tasks
zhangchi0104 opened this issue May 20, 2024 · 0 comments
Open
2 of 7 tasks
Labels
bug a bug in one of the components

Comments

@zhangchi0104
Copy link

Description

The image picker is closed immediately closed after choosing an option

Related to

  • Components
  • Demo
  • Docs
  • Typings

Steps to reproduce

  1. click the button on UI to open the image picker
  2. Choose any option

Expected behavior

the action sheet closes until image is choen

Actual behavior

the image picker closes immediately with the action sheet

More Info

Code snippet

type ChooseImageProviderProps = React.PropsWithChildren;
interface ChooseImageMenuProps {
  visible: boolean;
  imagePickerOptions: ImagePickerOptions;
  onChooseImage: (result: ImagePickerResult) => void;
  onPermissionDeny: (reason: any) => void;
  onDismiss?: () => void;
}
type PrmomiseResolveReject = {
  resolve: (value: ImagePickerResult) => void;
  reject: (reason: any) => void;
};

const ChooseImageMenu: React.FC<ChooseImageMenuProps> = ({
  visible,
  onChooseImage,
  onPermissionDeny,
  imagePickerOptions,
  onDismiss,
}) => {
  const options: ButtonProps[] = useMemo(() => {
    return [
      {
        label: 'From Media Library',
        onPress: () =>
          setTimeout(async () => {
            const permissionResult = await requestMediaLibraryPermissionsAsync();
            if (!permissionResult.granted) {
              onPermissionDeny(permissionResult);
            }
            const asset = await launchImageLibraryAsync(imagePickerOptions);
            onChooseImage(asset);
          }, 100),
      },
      {
        label: 'From Camera',
        onPress: () =>
          setTimeout(async () => {
            const permissionResult = requestCameraPermissionsAsync();
            if (!permissionResult) {
              onPermissionDeny(permissionResult);
            }
            const asset = await launchCameraAsync(imagePickerOptions);
            onChooseImage(asset);
          }, 100),
      },
    ];
  }, [imagePickerOptions, onChooseImage, onPermissionDeny]);

  return (
    <ActionSheet
      useSafeArea
      migrateDialog
      title={'Choose Image'}
      message={'Choose an image from'}
      visible={visible}
      options={options}
      onDismiss={onDismiss}
    />
  );
};

Screenshots/Video

Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-05-20.at.18.14.56.mp4

Environment

  • React Native version: 0.73.3
  • React Native UI Lib version: 7.21.1
  • expo: 50.0.14
  • expo-image-picker: 14.7.1

Affected platforms

  • Android
  • iOS
  • Web
@zhangchi0104 zhangchi0104 added the bug a bug in one of the components label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug a bug in one of the components
Projects
None yet
Development

No branches or pull requests

1 participant