Wrong PropType for style props in 2.0.0
See original GitHub issueBug report
In 2.0.0 PropTypes for a lot of styles have been changed from ViewPropTypes.style
to PropTypes.object
(see PR#2338 for example). However this is incorrect.
The prop type for styles should not be PropTypes.object
as this will lead to React warnings when providing arrays, e.g. like this:
<Header containerStyle={[t.borderB0, t.pX1, t.pY1, { backgroundColor: "white" }]} ... />
Warning: Failed prop type. Invalid prop
containerStyle
of typearray
supplied toHeader
, expectedobject
…
Meany people might not be familiar with this syntax but it is perfectly legal and commonly used with frameworks such as Tailwind CSS and similar.
A simple fix would be to replace all occurrences of PropTypes.object
for styles with PropTypes.oneOfType([PropTypes.object, PropTypes.array])
instead.
Environment info
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Memory: 500.18 MB / 16.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.14.1 - ~/.nvm/versions/node/v12.14.1/bin/node
npm: 6.14.5 - ~/.nvm/versions/node/v12.14.1/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 19, 22, 23, 28, 29
Build Tools: 28.0.3, 29.0.3, 30.0.0
System Images: android-22 | Google APIs ARM EABI v7a, android-22 | Google APIs Intel x86 Atom, android-23 | Android Wear ARM EABI v7a, android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom, android-28 | Wear OS Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-29 | Google Play Intel x86 Atom, android-R | Google Play Intel x86 Atom
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6514223
Xcode: 11.5/11E608c - /usr/bin/xcodebuild
npmPackages:
react: ~16.9.0 => 16.9.0
react-native: ~0.61.4 => 0.61.5
Library version: x.x.x
Steps to reproduce
Pass styles as array like this will generate a PropTypes
warning:
<Header containerStyle={[{ padding: 1 }, { backgroundColor: "white" }]} ... />
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top GitHub Comments
@arabold I agree, but it wasn’t due to any changes made here or in 2.0.1 or 2.0.2. I would guess that if you moved to 1.2.7, you would see the same warning. This is a separate issue that someone would need to write a issue ticket on.
Absolutely! I only fixed the styles property in my original PR. I’ll probably create a new one if nobody else is quicker.