-
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
[feature request] useTheme hook #676
Comments
Hi! Thanks for advice 👍 We'll definitely think about this. Did you know we have withStyles HOC? This will also add import { withStyles } from 'react-native-ui-kitten';
const MyComponent = (props) => (
<View style={{ backgroundColor: props.theme['color-primary-default'] }} />
);
export const MyThemedComponent = withStyles(MyComponent); Btw to launch playground app in dev mode consider following in this guide P.S: Just seen we forgot to mention the feature described above in docs :) |
Hi, I used some of yours internal exports, hopefully that's ok.
usage:
I would appreciate if you point me on possible errors. |
@Veikedo your code does the same, but it memoizes style object rather than passing it to props like it does |
@artyorsh yeah, it's the idea to do the same but with hooks rather than HOC. |
Btw, why not use a plain object instead of
vs current:
is it to make it lazy? |
@Veikedo nice notice. It's in our backlog. We currently think about simplifying this APIs, and appreciate any ideas. Your solution has one lack: in case theme contains more parameters: not only colors but global border-radius etc (sometimes it will) - there is no way to get it from theme |
@Veikedo We also have already some scripts to generate typescript interfaces for theme, component parameters and other Eva-based things, so it can make work autocomplete in your IDE, but it is also a beta feature I also want to answer one question that you probably might have: |
This, unfortunately, doesn't work for my case. |
@henoktsegaye you should use import { withStyles } from '@ui-kitten/components';
const ThemedComponent = withStyles(MyComponent, theme => ({
container: {
backgroundColor: theme['color-primary-default'],
},
})); |
@artyorsh I don't want to put it in a style, I want to have it as a value |
@henoktsegaye when using const backgroundColor = props.themedStyle.container.backgroundColor; |
Issue type
I'm submitting a ...
Issue description
Current behavior:
Not implemented yet.
Expected behavior:
Exposing a custom hook
useTheme
to access to theme context value.Using this hook we can be able to access the current value theme in this manner:
e.x:
Related code:
Adding a useContext consuming ThemeContext.
Other information:
I have a fork with
useTheme
implemented with tests, but im not able to start expo app -.-It's not finished yet but if maintainers are agree and see useful this feature im glad to keep working on this pr. link to repo with useTheme: https://github.com/x0s3/react-native-ui-kitten
Im open to talk else feel free to close this feature request :)
The text was updated successfully, but these errors were encountered: