Skip to content

Commit

Permalink
Merge pull request Expensify#31309 from VickyStash/ts-migration/offli…
Browse files Browse the repository at this point in the history
…neIndicator-component
  • Loading branch information
cead22 authored Dec 1, 2023
2 parents 3e86173 + d582daf commit 16c5d39
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 69 deletions.
69 changes: 0 additions & 69 deletions src/components/OfflineIndicator.js

This file was deleted.

52 changes: 52 additions & 0 deletions src/components/OfflineIndicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React, {useMemo} from 'react';
import {StyleProp, View, ViewStyle} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useWindowDimensions from '@hooks/useWindowDimensions';
import useThemeStyles from '@styles/useThemeStyles';
import variables from '@styles/variables';
import Icon from './Icon';
import * as Expensicons from './Icon/Expensicons';
import Text from './Text';

type OfflineIndicatorProps = {
/** Optional styles for container element that will override the default styling for the offline indicator */
containerStyles?: StyleProp<ViewStyle>;

/** Optional styles for the container */
style?: StyleProp<ViewStyle>;
};

function OfflineIndicator({style, containerStyles}: OfflineIndicatorProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {isSmallScreenWidth} = useWindowDimensions();

const computedStyles = useMemo((): StyleProp<ViewStyle> => {
if (containerStyles) {
return containerStyles;
}

return isSmallScreenWidth ? styles.offlineIndicatorMobile : styles.offlineIndicator;
}, [containerStyles, isSmallScreenWidth, styles.offlineIndicatorMobile, styles.offlineIndicator]);

if (!isOffline) {
return null;
}

return (
<View style={[computedStyles, styles.flexRow, styles.alignItemsCenter, style]}>
<Icon
src={Expensicons.OfflineCloud}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
/>
<Text style={[styles.ml3, styles.chatItemComposeSecondaryRowSubText]}>{translate('common.youAppearToBeOffline')}</Text>
</View>
);
}

OfflineIndicator.displayName = 'OfflineIndicator';

export default OfflineIndicator;

0 comments on commit 16c5d39

Please sign in to comment.