Skip to content

Commit

Permalink
Use SafeAreaView
Browse files Browse the repository at this point in the history
  • Loading branch information
pnthach95 committed Dec 8, 2023
1 parent 6f3ad93 commit 09fdc15
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/components/connectstatus/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@ import {useTranslation} from 'react-i18next';
import {View} from 'react-native';
import {NetworkConsumer} from 'react-native-offline';
import {Text, useTheme} from 'react-native-paper';
import {useSafeAreaPaddingTop} from 'theme/styles';
import {SafeAreaView} from 'react-native-safe-area-context';

/**
* Connect Status
*/
const ConnectStatus = () => {
const {t} = useTranslation();
const {colors} = useTheme();
const safeInsets = useSafeAreaPaddingTop();
const box = {
backgroundColor: colors.error,
const errorBox = {
backgroundColor: colors.errorContainer,
};
const errorBoxText = {
color: colors.onErrorContainer,
};

return (
<NetworkConsumer>
{({isConnected}) =>
isConnected ? (
<View style={safeInsets} />
) : (
<View className="p-3" style={[box, safeInsets]}>
<Text className="text-white">{t('no-internet-connection')}</Text>
</View>
)
}
</NetworkConsumer>
<SafeAreaView edges={['top']}>
<NetworkConsumer>
{({isConnected}) =>
!isConnected && (
<View className="p-3" style={errorBox}>
<Text style={errorBoxText}>{t('no-internet-connection')}</Text>
</View>
)
}
</NetworkConsumer>
</SafeAreaView>
);
};

Expand Down

0 comments on commit 09fdc15

Please sign in to comment.