Untitled

 avatar
unknown
plain_text
a month ago
922 B
2
Indexable
import React, { useEffect, useState } from 'react';
import { AppState, Text, View } from 'react-native';

export default function App() {
  const [appState, setAppState] = useState(AppState.currentState);

  useEffect(() => {
    const subscription = AppState.addEventListener('change', (nextAppState) => {
      setAppState(nextAppState);
      if (nextAppState === 'background') {
        // Hide sensitive data when app is in the background
        console.log('App moved to background. Hide sensitive data.');
      } else if (nextAppState === 'active') {
        console.log('App is active.');
      }
    });

    return () => {
      subscription.remove();
    };
  }, []);

  return (
    <View>
      {appState === 'background' ? (
        <Text>App is in the background. Sensitive data is hidden.</Text>
      ) : (
        <Text>App is active.</Text>
      )}
    </View>
  );
}
Leave a Comment