Skip to content

Commit

Permalink
wire up appstate subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr committed Feb 26, 2024
1 parent 0e60afe commit 845427d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions ios/RCTShareExtensionHandlerModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

NSString *const ShareExtensionGroupIdentifier = @"group.com.new-expensify";
NSString *const ShareExtensionFilesKey = @"ShareFiles";
NSString *const ShareImageFileExtension = @".png";

@implementation RCTShareExtensionHandlerModule

Expand Down
29 changes: 23 additions & 6 deletions src/pages/share/ShareRootPage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
import React, {useEffect} from 'react';
import {View} from 'react-native';
import React, {useEffect, useRef} from 'react';
import type {AppStateStatus} from 'react-native';
import {AppState, View} from 'react-native';
import Text from '@components/Text';
import ShareExtensionHandlerModule from '@src/modules/ShareExtensionHandlerModule';

// type ShareRootPageProps = {};

export default function ShareRootPage() {
const appState = useRef(AppState.currentState);

const handleAppStateChange = (nextAppState: AppStateStatus) => {
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
ShareExtensionHandlerModule.processFiles((processedFiles) => {
// eslint-disable-next-line no-console
console.log('PROCESSED FILES ', processedFiles);
});
}

appState.current = nextAppState;
// eslint-disable-next-line no-console
console.log('AppState', appState.current);
};

useEffect(() => {
ShareExtensionHandlerModule?.processFiles((processedFiles) => {
// eslint-disable-next-line no-console
console.warn('PROCESSED FILES ', processedFiles);
});
const appStateSubscription = AppState.addEventListener('change', handleAppStateChange);

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

return (
Expand Down

0 comments on commit 845427d

Please sign in to comment.