Closed sebastienlabine closed 1 year ago
Possible, maybe, but I'm not sure that would be ideal. iOS wouldn't work with that implementation since ActionSheetIOS doesn't support that. Also, showActionSheetWithOptions
doesn't return anything, so making it async wouldn't matter anyway.
Here's an idea using state...
const [response, setResponse] = useState(null);
useEffect(() => {
if (response) {
// something we care about with response
}
}, [response]);
const callback = async (index) => {
switch (index) {
case 0:
setResponse(await someAsyncFunction());
break;
default:
setResponse();
}
}
const onPress = () => {
showActionSheetWithOptions(options, callback);
}
Yes this is pretty much what i’m doing right now but I really don’t find it intuitive. My guess was that it’s natively not supported that’s why the option is not available.
My use case was about a reusable hook that lets pick images from multiple sources (camera, media library or document picker).
so I need to do
const [showPicker, {isLoading, assets}] = useMediaPicker();
useEffect(()=> {
if(assets) {}
},[assets]);
await showPicker();
Instead of only
var assets = await showPicker();
ˋ``
Could it be possible to allow us to await the result of the callback and return it?