-
Notifications
You must be signed in to change notification settings - Fork 960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(components): add theming hooks #782
Conversation
hi @artyorsh. Could you explain your motivation why you decide do not use
Thanks. |
Hi @vomchik 👋 Before I start to explain the motivation, let me describe the goals of this function:
My motivation is to create an API similar that we have out of the box in React Native (I mean similar to I understand that this might be a little confusing to use Thanks for the review 👍 |
Happy New Year! I see, thanks for the answer. i have a few suggestions:
Currently, I use own style hook with next API
|
I really like this new Also, if you use the For now I've followed @vomchik idea and created a function to turn this API into something a bit less confusing for me, I'll leave it here for inspiration: // In a utils.ts file
import { StyleSheet } from 'react-native';
import { useStyleSheet } from '@ui-kitten/components';
export function makeUseStyles<T>(
styles: StyleSheet.NamedStyles<T>,
): () => StyleSheet.NamedStyles<T> {
// eslint-disable-next-line react-hooks/rules-of-hooks
const UIKStyleSheet = useStyleSheet(styles);
const useStyles = () => UIKStyleSheet.create();
return useStyles;
}
// In a component's file
import { makeUseStyles } from '@app/utils';
const useStyles = makeUseStyles({
text: {
color: 'text-hint-color',
},
});
function Label({children}) {
const styles = useStyles();
return (
<Text style={styles.text}>
{children}
</Text>
);
} |
Please read and mark the following check list before creating a pull request:
Short description of what this resolves:
Adds
useTheme
hook:Returns the theme from nearest ThemeProvider
([feature request] useTheme hook #676, Hooks #752)
Adds
useStyleSheet
hook:Takes a theme provided by ApplicationProvider or ThemeProvider and applies it to style.
Adds documentation examples for new hooks and
styled
andwithStyles
HOCs.Improves performance of mapping theme by doing this once ThemeProvider is rendered instead of doing it each time cunsuming components are rendered.
Resolves accessing theme values from
theme
prop provided bywithStyles
(issue comment)Closes #752