khevamann / rn-responsive-styles

Responsive styles for react-native and react-native-web
MIT License
39 stars 3 forks source link

Style classnames with regex reserved characters get missed in overrides #24

Closed StefanWallin closed 7 months ago

StefanWallin commented 7 months ago

I usually write my style names with a $ name prefix like this:

const $headerText: TextStyle = {
  ...
}

If you make an override with any character that is a valid regex operator character in it's name then the overrides will not apply anymore due to how the regex is created in https://github.com/khevamann/rn-responsive-styles/blob/main/src/hooks/useResponsiveStyle.ts#L23. I would propose that we either put a note in the Readme about this fact or plug in some workaround to escape or otherwise make the classname not interfere with the override regex.

khevamann commented 7 months ago

Hi @StefanWallin, Yes I knew this was going to cause someone an issue at some point. I could make the pattern a little less common, like using $@$ as the prefix or something else random. Although it feels a little hacky, do you think adding this to the README is enough or do you think we should go ahead with a slightly more complex identifier like $@$

khevamann commented 7 months ago

Actually I think it could just be more exact, I can think of a pattern later this week

khevamann commented 7 months ago

@StefanWallin I have made the regex types stricter and sanitized the style names. This should fix the issues you were encountering, let me know if that is not the case or if you have any comments/ feedback on that. They have been published in V2.2.0 on NPM