react-native-a11y
Version:
Improvements of a11y for ReactNative, this library improve work with reader and keyboard focus and reader in general.
25 lines • 807 B
JavaScript
import { useState, useMemo } from "react";
import { StyleSheet } from "react-native";
export const useFocusStyle = (focusStyle, onFocusChange) => {
const [focused, setFocusStatus] = useState(false);
const onFocusChangeHandler = event => {
setFocusStatus(event.nativeEvent.isFocused);
onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(event);
};
const fStyle = useMemo(() => {
if (!focusStyle) return focused ? styles.defaultHighlight : undefined;
return typeof focusStyle === "function" ? focusStyle({
focused
}) : focusStyle;
}, [focused, focusStyle]);
return {
onFocusChangeHandler,
fStyle
};
};
const styles = StyleSheet.create({
defaultHighlight: {
backgroundColor: "#9999"
}
});
//# sourceMappingURL=useFocusStyle.js.map