erksch / react-native-wheely

An all JavaScript wheel picker for react-native without any native code.
413 stars 59 forks source link

Make text color respond to Dark Mode and boolean changes #43

Closed ucheNkadiCode closed 1 year ago

ucheNkadiCode commented 1 year ago

Thank you for making this package! Definitely a better alternative to the react native wheel picker android package.

My app supports dark mode, but every time I try to change the itemTextStyle from white to black based on the Dark Mode theme, no update occurs. It's the same issue if you want certain boolean values to affect the text

In the mean time I simply went to lib/wheelpickeritem.js and changed

/**
 * We enforce that this component will not rerender after the initial render.
 * Therefore props that change on every render like style objects or functions
 * do not need to be wrapped into useMemo and useCallback.
 */
() => true);

to

exports.default = react_1.default.memo(WheelPickerItem, 
/**
 * This component is now able to rerender when props change but won't otherwise.
 */
() => false);

However, I don't think this solution is performant

erksch commented 1 year ago

Disabling memoization is not advised because it will rerender every item in the picker uncontrollably. You can try to force the component to rerender using key:

<WheelPicker
  key={`mode-{isDarkModeEnabled ? 'dark' : 'light'}`}
  ...
/>

Haven't tried it though.

erksch commented 1 year ago

Closing this, feel free to reopen if the proposed solution does not work.

ucheNkadiCode commented 1 year ago

Hey @erksch forgot to respond! This actually worked for my app and is in production. Thank you!