Skip to content

Pass nextProps into calcTheme #77

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

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/components/themr.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {

constructor(...args) {
super(...args)
this.theme_ = this.calcTheme()
this.theme_ = this.calcTheme(this.props)
}

getWrappedInstance() {
Expand All @@ -97,8 +97,8 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
return this.refs.wrappedInstance
}

getNamespacedTheme() {
const { themeNamespace, theme } = this.props
getNamespacedTheme(props) {
const { themeNamespace, theme } = props
if (!themeNamespace) return theme

if (themeNamespace && !theme) {
Expand All @@ -119,9 +119,9 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
)
}

getThemeNotComposed() {
const { theme } = this.props
if (theme) return this.getNamespacedTheme()
getThemeNotComposed(props) {
const { theme } = props
if (theme) return this.getNamespacedTheme(props)
if (config.localTheme) return config.localTheme
return this.getContextTheme()
}
Expand All @@ -132,23 +132,23 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
: {}
}

getTheme() {
const { composeTheme } = this.props
getTheme(props) {
const { composeTheme } = props
return composeTheme === COMPOSE_SOFTLY
? {
...this.getContextTheme(),
...config.localTheme,
...this.getNamespacedTheme()
...this.getNamespacedTheme(props)
}
: themeable(
themeable(this.getContextTheme(), config.localTheme),
this.getNamespacedTheme()
this.getNamespacedTheme(props)
)
}

calcTheme() {
const { composeTheme } = this.props
return composeTheme ? this.getTheme() : this.getThemeNotComposed()
calcTheme(props) {
const { composeTheme } = props
return composeTheme ? this.getTheme(props) : this.getThemeNotComposed(props)
}

shouldComponentUpdate(nextProps) {
Expand All @@ -158,7 +158,7 @@ export default (componentName, localTheme, options = {}) => ThemedComponent => {
theme !== nextProps.theme ||
themeNamespace !== nextProps.themeNamespace
) {
this.theme_ = this.calcTheme()
this.theme_ = this.calcTheme(nextProps)
}
return true
}
Expand Down