我想创建一个钩子 useThemeStyled
在我的样式中用React-Native获得react-navigation主题。
import { useTheme } from "@react-navigation/native";
import { Theme } from "@react-navigation/native/lib/typescript/src/types";
export const HomeScreen = () => {
const sylings = useThemeStyled(styles);
return (
<View>
<Text style={sylings.title}>HomeScreen</Text>
</View>
);
};
const styles = (theme: Theme) => ({
title: {
color: theme.colors.text
}
});
const useThemeStyled = (style: (theme: Theme) => any) => {
const theme = useTheme();
return StyleSheet.create(style(theme));
};
是 import { Theme } from "@react-navigation/native/lib/typescript/src/types";
正确吗?
有没有一种方法可以不用定义 :Theme
类型为主题参数,当声明 const styles ...
?
使用 typeof
type Theme = typeof DefaultTheme;