You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an interest and idea to improve PlatformColor support on Android in order to align it with the way it's implemented on iOS
Problem
Currently, to work with theme updates and updating colors is made possible by Appearance module via useColorScheme and utilizing context based on example.
This is a common approach but it has following issues:
Context has to be created
Multiple styles and merging of them needs to be done
Component updates
PlatformColor
There's PlatformColor which helps to get rid of style updates, creation of additional code, and the color can simply be used inside of StyleSheet and no listeners and context hast to be created to simply updated the color on the fly...BUT only on iOS, since on Android we either need to update the whole activity (which is sub-optiomal).
Possible solution
While searching for a solution and going through the code, I noticed that when providing backgroundColor to View (I'm taking View as an example, it's the same logic with other components), in BaseViewManagerhere, the actual value is being converted from Object to Integer and underlying ReactViewGroup and others receive a simple Integer.
Would it be more rational to provide Object down to ReactViewGroup and other components, and do a conversion there while keeping the original Object and adding onConfigurationChanged (inside the same ReactViewGroup), and when new configuration comes then simply re-apply the color?
While it sounds as something simple, I'm wondering whether it would be correct to do it the way I described? Since the core logic and tests rely on to Integer everywhere. Or is there other place where it could be applied which I missed?
I will be more than happy to create a PR with changes to properties and tests if this is the way, since I believe it will simplify the workload which can be done with theme switching. Thank you!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there!
I have an interest and idea to improve
PlatformColor
support on Android in order to align it with the way it's implemented on iOSProblem
Currently, to work with theme updates and updating colors is made possible by
Appearance
module viauseColorScheme
and utilizing context based on example.This is a common approach but it has following issues:
PlatformColor
There's
PlatformColor
which helps to get rid of style updates, creation of additional code, and the color can simply be used inside ofStyleSheet
and no listeners and context hast to be created to simply updated the color on the fly... BUT only on iOS, since on Android we either need to update the whole activity (which is sub-optiomal).Possible solution
While searching for a solution and going through the code, I noticed that when providing
backgroundColor
toView
(I'm takingView
as an example, it's the same logic with other components), inBaseViewManager
here, the actual value is being converted fromObject
toInteger
and underlyingReactViewGroup
and others receive a simpleInteger
.Would it be more rational to provide
Object
down toReactViewGroup
and other components, and do a conversion there while keeping the originalObject
and addingonConfigurationChanged
(inside the sameReactViewGroup
), and when new configuration comes then simply re-apply the color?While it sounds as something simple, I'm wondering whether it would be correct to do it the way I described? Since the core logic and tests rely on to
Integer
everywhere. Or is there other place where it could be applied which I missed?I will be more than happy to create a PR with changes to properties and tests if this is the way, since I believe it will simplify the workload which can be done with theme switching. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions