import { Loader, Popup } from './common'; import React from 'react'; import type { GestureResponderEvent, ViewStyle, TextStyle, StyleProp, } from 'react-native'; import { View, StyleSheet } from 'react-native'; import NetInfo from '@react-native-community/netinfo'; import { moderateScale } from 'react-native-size-matters'; export type AwesomeContainerProps = { showPopup?: boolean; popupType?: 'Danger' | 'Success' | 'Warning'; popupTitle?: string; popupMessage?: string; onPressPopup?: (event: GestureResponderEvent) => void; onPressSecondaryButton?: (event: GestureResponderEvent) => void; children: React.ReactNode; headerTextStyle?: StyleProp; isLoading?: boolean; buttonText?: string; secondaryButtonTextStyle?: StyleProp; secondaryButtonStyle?: StyleProp; secondaryButtonText?: string; style?: StyleProp; contentStyle?: StyleProp; iconContentStyle?: StyleProp; iconColor?: string; textBodyStyle?: StyleProp; buttonStyle?: StyleProp; overlayStyle?: StyleProp; buttonTextStyle?: StyleProp; spinnerColor?: string; loaderOverlay?: boolean; spinner?: | 'CircleFade' | 'Plane' | 'Chase' | 'Bounce' | 'Wave' | 'Pulse' | 'Flow' | 'Swing' | 'Circle' | 'Grid' | 'Fold' | 'Wander'; }; export function Container({ showPopup, popupType, popupTitle, popupMessage, onPressPopup, children, isLoading, buttonText, style, contentStyle, iconColor, iconContentStyle, textBodyStyle, buttonStyle, buttonTextStyle, spinner, spinnerColor, headerTextStyle, secondaryButtonText, secondaryButtonStyle, secondaryButtonTextStyle, onPressSecondaryButton, loaderOverlay, overlayStyle, }: AwesomeContainerProps) { const [isConnectedToTheWifi, setIsConnectedToTheWifi] = React.useState(true); const updateNet = () => setIsConnectedToTheWifi(true); React.useEffect( () => NetInfo.addEventListener((state) => { setIsConnectedToTheWifi(!!state.isConnected); }), [] ); return ( <> {!isLoading || loaderOverlay ? children : null} {isLoading && !loaderOverlay && ( )} {isLoading && loaderOverlay && ( )} ); } const styles = StyleSheet.create({ main: { paddingHorizontal: moderateScale(18), }, loaderContainer: { ...StyleSheet.absoluteFillObject, justifyContent: 'center', alignItems: 'center', backgroundColor: 'rgba(0, 0, 0, 0.5)', }, });