Skip to content

Commit f400928

Browse files
committed
feat(utils): ⚡ add useWebFocusRing hook
1 parent 7e18eaf commit f400928

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/utils/hooks.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import { useEffect, useMemo, useRef, useState } from "react";
99
import { LayoutChangeEvent, Platform } from "react-native";
1010
import { useSharedValue } from "react-native-reanimated";
11+
import {
12+
FocusRingAria,
13+
useFocusRing as useWebOnlyFocusRing,
14+
} from "@react-aria/focus";
1115

1216
export const useOnFocus = () => {
1317
const focused = useSharedValue(0);
@@ -113,3 +117,20 @@ export const useLayout = () => {
113117

114118
return { onLayout, layout };
115119
};
120+
121+
export const useWebFocusRing = () => {
122+
let useFocusRingHook: () => FocusRingAria;
123+
124+
if (Platform.OS === "web") {
125+
// Import the hook only if the platform is web
126+
useFocusRingHook = useWebOnlyFocusRing;
127+
} else {
128+
// If not on web platform, provide a dummy implementation
129+
useFocusRingHook = () => ({
130+
isFocusVisible: false,
131+
isFocused: false,
132+
focusProps: {},
133+
});
134+
}
135+
return useFocusRingHook();
136+
};

0 commit comments

Comments
 (0)