-
-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): offline header shows that app is offline
- Loading branch information
Showing
30 changed files
with
178 additions
and
19 deletions.
There are no files selected for viewing
Loading
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
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,25 @@ | ||
{ | ||
"name": "@suite-native/connection-status", | ||
"version": "1.0.0", | ||
"private": true, | ||
"license": "See LICENSE.md in repo root", | ||
"sideEffects": false, | ||
"main": "src/index", | ||
"scripts": { | ||
"lint:js": "yarn g:eslint '**/*.{ts,tsx,js}'", | ||
"depcheck": "yarn g:depcheck", | ||
"type-check": "yarn g:tsc --build" | ||
}, | ||
"dependencies": { | ||
"@react-native-community/netinfo": "11.3.2", | ||
"@suite-common/icons": "workspace:*", | ||
"@suite-native/atoms": "workspace:*", | ||
"@suite-native/intl": "workspace:*", | ||
"@suite-native/settings": "workspace:*", | ||
"@trezor/styles": "workspace:*", | ||
"react": "18.2.0", | ||
"react-native": "0.74.1", | ||
"react-native-safe-area-context": "4.10.3", | ||
"react-redux": "8.0.7" | ||
} | ||
} |
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,45 @@ | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
import { View } from 'react-native'; | ||
|
||
import { Icon } from '@suite-common/icons'; | ||
import { Text, HStack } from '@suite-native/atoms'; | ||
import { Translation } from '@suite-native/intl'; | ||
import { prepareNativeStyle, useNativeStyles } from '@trezor/styles'; | ||
|
||
import { useIsOfflineBannerVisible } from './useIsOfflineBannerVisible'; | ||
|
||
const containerStyle = prepareNativeStyle(utils => ({ | ||
backgroundColor: utils.colors.backgroundAlertYellowBold, | ||
alignItems: 'center', | ||
})); | ||
|
||
const contentStyle = prepareNativeStyle<{ topSafeAreaInset: number }>( | ||
(utils, { topSafeAreaInset }) => ({ | ||
marginTop: topSafeAreaInset, | ||
paddingTop: utils.spacings.small, | ||
paddingBottom: 12, | ||
alignItems: 'center', | ||
}), | ||
); | ||
|
||
export const OfflineBanner = () => { | ||
const { applyStyle } = useNativeStyles(); | ||
const { top: topSafeAreaInset } = useSafeAreaInsets(); | ||
|
||
const isOfflineBannerVisible = useIsOfflineBannerVisible(); | ||
|
||
if (!isOfflineBannerVisible) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<View style={applyStyle(containerStyle)}> | ||
<HStack style={applyStyle(contentStyle, { topSafeAreaInset })}> | ||
<Icon name="wifiSlash" size="mediumLarge" /> | ||
<Text> | ||
<Translation id="generic.offline" /> | ||
</Text> | ||
</HStack> | ||
</View> | ||
); | ||
}; |
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,3 @@ | ||
export * from './OfflineBanner'; | ||
export * from './useOfflineBannerAwareSafeAreaInsets'; | ||
export * from './useIsOfflineBannerVisible'; |
12 changes: 12 additions & 0 deletions
12
suite-native/connection-status/src/useIsOfflineBannerVisible.tsx
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,12 @@ | ||
import { useSelector } from 'react-redux'; | ||
|
||
import { useNetInfo } from '@react-native-community/netinfo'; | ||
|
||
import { selectIsOnboardingFinished } from '@suite-native/settings'; | ||
|
||
export const useIsOfflineBannerVisible = () => { | ||
const isOnboardingFinished = useSelector(selectIsOnboardingFinished); | ||
const { isConnected } = useNetInfo(); | ||
|
||
return !isConnected && isOnboardingFinished; | ||
}; |
12 changes: 12 additions & 0 deletions
12
suite-native/connection-status/src/useOfflineBannerAwareSafeAreaInsets.tsx
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,12 @@ | ||
import { EdgeInsets, useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
|
||
import { useIsOfflineBannerVisible } from './useIsOfflineBannerVisible'; | ||
|
||
// If offline banner is visible, return 0 for top inset, otherwise return the top inset from safe area insets | ||
// this is because the offline banner is displayed on top of the screen and we don't want to add any top padding | ||
export const useOfflineBannerAwareSafeAreaInsets = () => { | ||
const { top, ...rest } = useSafeAreaInsets(); | ||
const isOfflineBannerVisible = useIsOfflineBannerVisible(); | ||
|
||
return { top: isOfflineBannerVisible ? 0 : top, ...rest } as EdgeInsets; | ||
}; |
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,12 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"compilerOptions": { "outDir": "libDev" }, | ||
"references": [ | ||
{ "path": "../../suite-common/icons" }, | ||
{ "path": "../atoms" }, | ||
{ "path": "../intl" }, | ||
{ "path": "../settings" }, | ||
{ "path": "../../packages/styles" } | ||
], | ||
"include": [".", "**/*.json"] | ||
} |
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
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
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
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
Oops, something went wrong.