Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,11 @@ export default class RNPickerSelect extends PureComponent {
onPress={onOpen}
activeOpacity={1}
{...touchableWrapperProps}
style={{
...touchableWrapperProps.style,
...defaultStyles.viewContainer,
...style.viewContainer
}}
Comment on lines +517 to +521
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Object-spread risks a crash and introduces a duplicate style prop

  1. touchableWrapperProps.style is spread directly. If the consumer omits the style key (default is {}), the value will be undefined, and { ...undefined } throws TypeError: Cannot convert undefined or null to object at runtime.
  2. Because touchableWrapperProps is already spread earlier ({...touchableWrapperProps}), you now pass two style props – one from the spread, one explicitly. This violates react/jsx-no-duplicate-props and whichever comes last wins, making the first silently ignored.
  3. React-Native encourages merging styles with an array, not by object-spreading. Arrays keep the original objects intact, play nicely with StyleSheet.flatten, and are more familiar to library consumers.
  4. ESLint / Prettier is already complaining about a missing trailing comma here (Insert ,). Switching to an array also resolves that.

Proposed fix:

-        {...touchableWrapperProps}
-        style={{
-          ...touchableWrapperProps.style,
-          ...defaultStyles.viewContainer,
-          ...style.viewContainer
-        }}
+        {...(() => {
+          // separate out style to avoid duplicate props
+          const { style: wrapperStyle, ...rest } = touchableWrapperProps;
+          return {
+            ...rest,
+            style: [
+              defaultStyles.viewContainer,
+              style.viewContainer,
+              wrapperStyle,          // may be undefined – safe in an array
+            ],
+          };
+        })()}

This:

• Prevents the crash when wrapperStyle is undefined.
• Removes the duplicate style prop.
• Uses the canonical React-Native array-merge pattern.
• Keeps later entries (wrapperStyle) overriding earlier ones, preserving existing semantics.

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 ESLint

[error] 520-520: Insert ,

(prettier/prettier)

🤖 Prompt for AI Agents
In src/index.js around lines 517 to 521, avoid spreading
touchableWrapperProps.style directly as it can be undefined causing a runtime
crash, and also avoid passing duplicate style props by spreading
touchableWrapperProps and then separately spreading style. Instead, merge styles
using a React-Native style array combining touchableWrapperProps.style,
defaultStyles.viewContainer, and style.viewContainer in order, ensuring no
duplicate style props and preventing crashes from undefined values. This also
resolves the missing trailing comma ESLint/prettier issue.

>
<View style={style.headlessAndroidContainer}>
{this.renderTextInputOrChildren()}
Expand Down