Skip to content

Commit

Permalink
CP-9602: K2 Clipboard (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
onghwan authored Dec 16, 2024
1 parent a084b68 commit cf7b3cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import React from 'react'
import { Text, ScrollView, View, Button } from '@avalabs/k2-alpine'
import { Link } from 'expo-router'
import BlurredBarsContentLayout from 'new/components/navigation/BlurredBarsContentLayout'
import { copyToClipboard } from 'new/utils/clipboard'

const PortfolioHomeScreen = (): JSX.Element => {
const handleCopyToClipboard = (): void => {
copyToClipboard('test')
}

return (
<BlurredBarsContentLayout>
<ScrollView
Expand All @@ -21,6 +26,9 @@ const PortfolioHomeScreen = (): JSX.Element => {
Go to Portfolio Assets
</Button>
</Link>
<Button type="primary" size="medium" onPress={handleCopyToClipboard}>
Copy "test" to clipboard
</Button>
<View sx={{ height: 800, width: 200, backgroundColor: 'orange' }} />
<View />
</ScrollView>
Expand Down
11 changes: 11 additions & 0 deletions packages/core-mobile/app/new/utils/clipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Clipboard from '@react-native-clipboard/clipboard'
import { showSnackbar } from './toast'

export const copyToClipboard = (str?: string, message = 'Copied'): void => {
if (str) {
Clipboard.setString(str)
showSnackbar(message)
} else {
Clipboard.setString('') //better to clean clipboard than let user paste something unintentionally
}
}

0 comments on commit cf7b3cc

Please sign in to comment.