-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added share feature (Receive screen only for now), enhanced Collapsed…
…QR with icon-only mode
- Loading branch information
Showing
6 changed files
with
278 additions
and
19 deletions.
There are no files selected for viewing
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,99 @@ | ||
import * as React from 'react'; | ||
import { Platform, TouchableOpacity } from 'react-native'; | ||
|
||
import QRCode from 'react-native-qrcode-svg'; | ||
import { captureRef } from 'react-native-view-shot'; | ||
import Share from 'react-native-share'; | ||
import { Icon } from 'react-native-elements'; | ||
|
||
import Button from './../components/Button'; | ||
|
||
import { localeString } from './../utils/LocaleUtils'; | ||
import { themeColor } from './../utils/ThemeUtils'; | ||
|
||
type QRCodeElement = React.ElementRef<typeof QRCode>; | ||
|
||
interface ShareButtonProps { | ||
value: string; | ||
qrRef: React.RefObject<QRCodeElement> | null; | ||
title?: string; | ||
icon?: any; | ||
noUppercase?: boolean; | ||
iconOnly?: boolean; | ||
onPress: () => Promise<void>; | ||
onShareComplete?: () => void; | ||
} | ||
|
||
export default class ShareButton extends React.Component<ShareButtonProps> { | ||
handlePress = async () => { | ||
const { onPress } = this.props; | ||
await onPress(); | ||
await this.shareContent(); | ||
}; | ||
|
||
shareContent = async () => { | ||
const { value, qrRef, onShareComplete } = this.props; | ||
try { | ||
if (!qrRef?.current) { | ||
return; | ||
} | ||
|
||
const svgElement = qrRef.current; | ||
const base64Data = await captureRef(svgElement, { | ||
format: 'png', | ||
quality: 1 | ||
}); | ||
|
||
await Share.open({ | ||
message: value, | ||
url: base64Data | ||
}); | ||
} catch (error) { | ||
// Share API throws error when share sheet closes, regardless of success | ||
console.log('Error in shareContent:', error); | ||
} finally { | ||
onShareComplete?.(); | ||
} | ||
}; | ||
|
||
render() { | ||
const { title, icon, noUppercase, iconOnly } = this.props; | ||
|
||
if (iconOnly) { | ||
return ( | ||
<TouchableOpacity | ||
// "padding: 5" leads to a larger area where users can click on | ||
style={{ padding: 5 }} | ||
onPress={this.handlePress} | ||
> | ||
<Icon | ||
name={'share'} | ||
size={27} | ||
color={themeColor('secondaryText')} | ||
/> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
return ( | ||
<Button | ||
title={title || localeString('general.share')} | ||
icon={ | ||
icon | ||
? icon | ||
: { | ||
name: 'share', | ||
size: 25 | ||
} | ||
} | ||
containerStyle={{ | ||
marginTop: 10, | ||
marginBottom: Platform.OS === 'android' ? 0 : 20 | ||
}} | ||
onPress={this.handlePress} | ||
secondary | ||
noUppercase={noUppercase} | ||
/> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.