-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add share button to receive screen (#310)
- Loading branch information
Daniel
committed
Jun 9, 2022
1 parent
8f62a42
commit ed03476
Showing
6 changed files
with
118 additions
and
77 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import * as rb from 'react-bootstrap' | ||
import Sprite from './Sprite' | ||
|
||
const checkIsWebShareAPISupported = () => { | ||
return !!navigator.share | ||
} | ||
|
||
const ShareButton = ({ value, className }) => { | ||
const handleShare = async () => { | ||
if (!checkIsWebShareAPISupported()) { | ||
console.error('Sharing failed: Web Share API not supported.') | ||
return | ||
} | ||
|
||
try { | ||
await navigator.share({ | ||
text: value, | ||
}) | ||
} catch (error) { | ||
console.error(`Sharing failed: ${error}`) | ||
} | ||
} | ||
|
||
return ( | ||
<rb.Button variant="outline-dark" className={className} onClick={handleShare}> | ||
<div className="d-flex align-items-center justify-content-center"> | ||
<Sprite symbol="share" className="me-1" width="20" height="20" /> | ||
Share | ||
</div> | ||
</rb.Button> | ||
) | ||
} | ||
|
||
export { ShareButton, checkIsWebShareAPISupported } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters