-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix:react-native-ratings integration in react-native-elements #3983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix:react-native-ratings integration in react-native-elements #3983
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR removes the external react-native-ratings dependency and implements a custom in-house rating solution by creating new AirbnbRating components with TapRating and SwipeRating functionality. This represents a breaking change that internalizes rating functionality within the react-native-elements library.
- Removes react-native-ratings dependency from multiple package.json files
- Implements custom TapRating and SwipeRating components from scratch
- Updates Rating and AirbnbRating components to use the new internal implementation
Reviewed Changes
Copilot reviewed 12 out of 18 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| website/package.json | Removes react-native-ratings dependency from website package |
| packages/base/package.json | Removes react-native-ratings dependency and updates testing dependencies |
| package.json | Updates testing library versions and Jest configuration |
| packages/base/src/Rating/Rating.tsx | Updates imports to use new internal SwipeRating component |
| packages/base/src/AirbnbRating/AirbnbRating.tsx | Updates imports to use new internal TapRating component |
| packages/base/src/AirbnbRating/TapRating.tsx | New custom TapRating component implementation |
| packages/base/src/AirbnbRating/SwipeRating.tsx | New custom SwipeRating component implementation |
| packages/base/src/AirbnbRating/components/Star.tsx | New Star component for rating functionality |
Comments suppressed due to low confidence (1)
packages/base/src/AirbnbRating/tests/SwipeRating.test.tsx:5
- This test is checking for exports from '../index' but the file being tested is SwipeRating.test.tsx. The test should actually test the SwipeRating component functionality rather than checking index exports.
const { Rating, AirbnbRating } = require('../index');
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [] // [getCurrentRating, onStartRating, position] |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The eslint-disable comment with empty dependency array is potentially problematic. The callback relies on getCurrentRating, onStartRating, and position which should be included in the dependency array or the disable comment should be justified.
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| [] // [getCurrentRating, onStartRating, position] | |
| [getCurrentRating, onStartRating, position] |
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [] // [getCurrentRating, onSwipeRating, position] |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the previous callback, this eslint-disable comment with empty dependency array is potentially problematic. The callback uses getCurrentRating, onSwipeRating, and position which should be in the dependency array.
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| [] // [getCurrentRating, onSwipeRating, position] | |
| [getCurrentRating, onSwipeRating, position] |
| }, | ||
| // | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| [] // [getCurrentRating, fractions, onFinishRating, setCurrentRating, minValue] |
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This eslint-disable comment with empty dependency array is also problematic. The callback depends on several functions and values that should be included in the dependency array to prevent stale closures.
| [] // [getCurrentRating, fractions, onFinishRating, setCurrentRating, minValue] | |
| [getCurrentRating, fractions, onFinishRating, setCurrentRating, minValue, ratingBackdropValue] |
| //@ts-ignore | ||
| const fractionsType: any = (props, propName, componentName) => { | ||
| if (props[propName]) { | ||
| const value = props[propName]; | ||
|
|
||
| if (typeof value === 'number') { | ||
| return value >= 0 && value <= 20 | ||
| ? null | ||
| : new Error( | ||
| `\`${propName}\` in \`${componentName}\` must be between 0 and 20` | ||
| ); | ||
| } | ||
|
|
||
| return new Error( | ||
| `\`${propName}\` in \`${componentName}\` must be a number` | ||
| ); | ||
| } | ||
| }; | ||
|
|
Copilot
AI
Jul 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using @ts-ignore to suppress TypeScript errors is not ideal. The fractionsType function should be properly typed instead of being suppressed.
| //@ts-ignore | |
| const fractionsType: any = (props, propName, componentName) => { | |
| if (props[propName]) { | |
| const value = props[propName]; | |
| if (typeof value === 'number') { | |
| return value >= 0 && value <= 20 | |
| ? null | |
| : new Error( | |
| `\`${propName}\` in \`${componentName}\` must be between 0 and 20` | |
| ); | |
| } | |
| return new Error( | |
| `\`${propName}\` in \`${componentName}\` must be a number` | |
| ); | |
| } | |
| }; | |
| const fractionsType: (props: Record<string, any>, propName: string, componentName: string) => Error | null = | |
| (props, propName, componentName) => { | |
| if (props[propName]) { | |
| const value = props[propName]; | |
| if (typeof value === 'number') { | |
| return value >= 0 && value <= 20 | |
| ? null | |
| : new Error( | |
| `\`${propName}\` in \`${componentName}\` must be between 0 and 20` | |
| ); | |
| } | |
| return new Error( | |
| `\`${propName}\` in \`${componentName}\` must be a number` | |
| ); | |
| } | |
| return null; | |
| }; |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Removed the toggle for selected state in star selection.
…and snapshot accuracy
|
Thank you @codewithshinde for making the subsequent updates so that all checks are now passing. I tested on the example app locally and all Additionally, I added a "Future Improvement" section below to address the above note from Copilot: I leveraged Claude to assist in my review of the Review
Suggested Future Changes1. Fix Variable Shadowing in TapRatingLocation: Issue: The function parameter Suggested Fix: Rename the parameter to avoid shadowing: - const starSelectedInPosition = (position: number) => {
+ const starSelectedInPosition = (selectedPosition: number) => {
if (typeof onFinishRating === 'function') {
- onFinishRating(position);
+ onFinishRating(selectedPosition);
}
- setPosition(position);
+ setPosition(selectedPosition);
};2. [Nitpick] Remove Unused DependencyIn "dependencies": {
- "@rn-vui/ratings": "^0.5.0",
"@types/react-native-vector-icons": "^6.4.10",
"color": "^3.2.1",After removing, run 3. [Nitpick] Remove Outdated CommentIn import React from 'react';
-// Assuming TapRating and SwipeRating are now available at the root level of 'react-native-ratings'
import TapRating, { type TapRatingProps as RatingProps } from './TapRating';This comment references Future Improvement Suggested:
|
Potential Bug from Manual TestingWhile doing further testing on the example app's ratings screen, I discovered that custom rating images don't work as expected in the SwipeRating component. When you set |
…ns/main fix:react-native-ratings integration in react-native-elements
…ns/main fix:react-native-ratings integration in react-native-elements
theianmay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Full review in comment above, merged and closed, thank you!
Motivation
Fixes # (issue) react-native-ratings Issues
Type of change
How Has This Been Tested?
exampleappChecklist
yarn docs-build-apiAdditional context