Skip to content

Commit

Permalink
🐛 Fix mobile sharing bar
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Gossens committed Mar 1, 2021
1 parent 6c0d948 commit 85eb57d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/react-chayns-contextmenu/component/ContextMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ const ContextMenu = React.forwardRef((props, ref) => {
if (!disableDialog && (chayns.env.isMobile || chayns.env.isTablet)) {
const { buttonType, selection } = await chayns.dialog.select({
type: 2,
list: items.map(({ text, icon }, index) => ({
name: text,
list: items.map(({ text, icon, stringName }, index) => ({
name: stringName
? TextString.getTextString(stringName, null, text)
: text,
value: index,
icon:
typeof icon === 'string' ? icon : `fa-${icon.iconName}`,
Expand Down
27 changes: 13 additions & 14 deletions src/react-chayns-sharingbar/component/SharingBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ function SharingBar({
});
}
}, []);

const mobileShare = sharingProvider.find(
(app) => app.id === 10 || app.id === 11
);
Expand All @@ -49,14 +48,25 @@ function SharingBar({
link = getDefaultShareLink();
}

if (!children && !textStringsLoaded) {
return null;
}

const indicator = children || [
<Icon icon="fal fa-share-alt" className="sharing-bar__icon" />,
<TextString stringName={'txt_chayns_components_sharingbar_share'}>
<span className="sharing-bar__text" />
</TextString>,
];

if (mobileShare) {
const onClick = (e) => {
share(mobileShare, link, linkText);

if (stopPropagation) e.stopPropagation();
};

return <div onClick={onClick}>{children}</div>;
return <div onClick={onClick}>{indicator}</div>;
}

const sharingItems = [];
Expand All @@ -75,24 +85,13 @@ function SharingBar({
icon: x.icon,
});
});
if (!children && !textStringsLoaded) return null;
return (
<div className={classNames('sharing-bar', className)} style={style}>
<ContextMenu
items={sharingItems}
childrenStyle={{ display: 'inline' }}
>
{children || [
<Icon
icon="fal fa-share-alt"
className="sharing-bar__icon"
/>,
<TextString
stringName={'txt_chayns_components_sharingbar_share'}
>
<span className="sharing-bar__text" />
</TextString>,
]}
{indicator}
</ContextMenu>
</div>
);
Expand Down
12 changes: 7 additions & 5 deletions src/react-chayns-sharingbar/component/sharingActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ function copyToClipboard(link) {
document.body.removeChild(aux);
}

function webShareApi(link, linkText) {
navigator.share({
url: link,
text: linkText,
});
async function webShareApi(link, linkText) {
try {
await navigator.share({
url: link,
text: linkText,
});
} catch (ignored) {}
}

export default function share(provider, link, linkText) {
Expand Down

0 comments on commit 85eb57d

Please sign in to comment.