Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {PickerStateProvider} from 'react-native-picker-select';
import {SafeAreaProvider} from 'react-native-safe-area-context';
import '../wdyr';
import {ActionSheetAwareScrollViewProvider} from './components/ActionSheetAwareScrollView';
import ActiveElementRoleProvider from './components/ActiveElementRoleProvider';
import ColorSchemeWrapper from './components/ColorSchemeWrapper';
import ComposeProviders from './components/ComposeProviders';
import {CurrentUserPersonalDetailsProvider} from './components/CurrentUserPersonalDetailsProvider';
Expand Down Expand Up @@ -115,7 +114,6 @@ function App() {
PickerStateProvider,
EnvironmentProvider,
CustomStatusBarAndBackgroundContextProvider,
ActiveElementRoleProvider,
ActionSheetAwareScrollViewProvider,
PlaybackContextProvider,
FullScreenContextProvider,
Expand Down
20 changes: 0 additions & 20 deletions src/components/ActiveElementRoleProvider/index.native.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions src/components/ActiveElementRoleProvider/index.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/ActiveElementRoleProvider/types.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/hooks/useActiveElementRole/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type UseActiveElementRole from './types';

const useActiveElementRole: UseActiveElementRole = () => null;

export default useActiveElementRole;
24 changes: 14 additions & 10 deletions src/hooks/useActiveElementRole/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import {useContext} from 'react';
import {ActiveElementRoleContext} from '@components/ActiveElementRoleProvider';
import {useSyncExternalStore} from 'react';
import type UseActiveElementRole from './types';

/**
* Listens for the focusin and focusout events and sets the DOM activeElement to the state.
* On native, we just return null.
*/
const useActiveElementRole: UseActiveElementRole = () => {
const {role} = useContext(ActiveElementRoleContext);
function subscribe(callback: () => void) {
document.addEventListener('focusin', callback);
document.addEventListener('focusout', callback);
return () => {
document.removeEventListener('focusin', callback);
document.removeEventListener('focusout', callback);
};
}

return role;
};
function getSnapshot() {
return document.activeElement?.role ?? null;
}

const useActiveElementRole: UseActiveElementRole = () => useSyncExternalStore(subscribe, getSnapshot);

export default useActiveElementRole;
Loading