Skip to content

Changing theme is not propagated to connectedComponents #910

@chaitanya-bhagavan

Description

@chaitanya-bhagavan

When StyleProvider theme is changed it does not get propagated to the ConnectedComponents(components that are decorated with connectStyle). After some debugging I found this issue is due to a bug in native-base-shoutem-theme connectStyle.js, specifically getOrSetStylesInCache method.

    getOrSetStylesInCache(context, props, styleNames, path) {
      if (themeCache && themeCache[path.join('>')]) {
        // console.log('**************');

        return themeCache[path.join('>')];
      } else {
        resolvedStyle = this.resolveStyle(context, props, styleNames);
        if (Object.keys(themeCache).length < 10000) {
          themeCache[path.join('>')] = resolvedStyle;
        }
        return resolvedStyle;
      }
    }

Looks like it is using the cached version of the theme for current component. The fix is to
remove the if block that is looking for the cached version of the style for the current component. The cache is still used for lookup of parent styles.

      getOrSetStylesInCache(context, props, styleNames, path) {
        resolvedStyle = this.resolveStyle(context, props, styleNames);
        if (Object.keys(themeCache).length < 10000) {
          themeCache[path.join('>')] = resolvedStyle;
        }
        return resolvedStyle;
      }

I have a sample code to demonstrate this issue Github repo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions