-
-
Notifications
You must be signed in to change notification settings - Fork 138
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
Using static theme (change theme without app reload) #47
Comments
|
In my first question I don't talk about dynamic theme I talk about static theme . This library is awesome but I have 2 major problem Second problem is static theme is very easy to use but dynamic is not as easy as static and also If I have 20+ theme . I MUST prebuild all themes and it need 20x resources |
@vitalets any idea? |
Your case is interesting. I agree that caching 20+ themes looks overhead and the best approach is to dynamically build selected theme. Currently this is not supported in EStyleSheet. But it can be done by changing two places as I described here: #22 (comment) I would appreciate I you play with it and share the results. |
@vitalets I think we can re-render all components by do following Assume we have
When we change theme , we change
(i know we lost states , but it is better than reloading application) |
Any update? |
@sm2017 sorry for delay, lost this thread. Approach looks good to me! By the way, could you show the whole example how you see this? For example with |
examples: comments examples: add theming readme changelog: dynamic theming
My method is in a HOC, but you can adapt it… withResponsive.ts import React, { View, ComponentType, FunctionComponent, useState } from 'react'
import EStyleSheet from 'react-native-extended-stylesheet'
const styles = EStyleSheet.create({
container: {
flex: 1,
},
})
export const withResponsive = (Component: ComponentType): ComponentType => {
const Responsive: FunctionComponent<unknown> = () => {
const [show, setShow] = useState<boolean>(true)
const build = () => {
setShow(false)
EStyleSheet.build()
setShow(true)
}
return (
<View style={styles.container} onLayout={build}>
{show ? <Component /> : null}
</View>
)
}
return Responsive
} |
1- Is it possible to use static theme and no app reload to theme change? for example when I want to change theme , Just call
EStyleSheet.build
andforceUpdate
again2- Is dynamic theme need cashing ? IS dynamic theme need stylesheet creation in every render() call?
The text was updated successfully, but these errors were encountered: