Reputation: 763
Hi we are using the following library in our app, It works fine in Android and iOS but in Huawei devices the Share.open() doesn't return anything.
This is the library which we are using to share some texts.
import Share from "react-native-share";
const message = "Text to share";
Share.open({
message,
}).then((res) => {
console.log(res);
return true;
}).catch((err) => {
console.log("Exception: ", err);
return false;
});
In Huawei device it does open up the sharing dialog and I can choose any app to share the message and after coming back to our app, the app logic cannot proceed because the promise is not returning any value.
Im testing on Huawei P40Pro device which has only HMS available. However, even the devices with both HMS and GMS having the same issue.
Appreciate any help on this.
Upvotes: 2
Views: 719
Reputation: 2035
I would suggest to use a different React Native Share component such as the Share component at https://docs.expo.dev/versions/latest/react-native/share/. I am using Expo and here is the sample code which accomplish the same text sharing feature as your code. Tested the sample code with Huawei Mate 30 Pro and iPhone, the React Native app sharing feature works fine.
import React from 'react';
import { Share, View, Button } from 'react-native';
export default function ShareExample() {
const onShare = async () => {
try {
const result = await Share.share({
message: 'React Native | A framework for building native apps using React',
});
if (result.action === Share.sharedAction) {
if (result.activityType) {
// shared with activity type of result.activityType
} else {
// shared
}
} else if (result.action === Share.dismissedAction) {
// dismissed
}
} catch (error) {
alert(error.message);
}
};
return (
<View style={{ marginTop: 50 }}>
<Button onPress={onShare} title="Share" />
</View>
);
}
Upvotes: 0