From 00abcb0fb0b3cb72d680c5ee7aa7c479ed68dfdf Mon Sep 17 00:00:00 2001 From: Andy Thurman Date: Tue, 3 Sep 2024 09:47:39 +0100 Subject: [PATCH 1/4] Replace defaultProps with default params in Star.tsx --- src/components/Star.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/Star.tsx b/src/components/Star.tsx index 2fe1a85..b451f98 100644 --- a/src/components/Star.tsx +++ b/src/components/Star.tsx @@ -23,7 +23,7 @@ export type StarProps = { starSelectedInPosition?: ( number ) => void; }; -const Star: React.FunctionComponent = props => { +const Star: React.FunctionComponent = ({starImage = STAR_IMAGE, selectedColor = "#f1c40f", unSelectedColor = "#BDC3C7", ...props}) => { const [selected, setSelected] = useState( false ); const springValue = new Animated.Value( 1 ); @@ -45,11 +45,8 @@ const Star: React.FunctionComponent = props => { }; const { - starImage, fill, size, - selectedColor, - unSelectedColor, isDisabled, starStyle } = props; From 6b284a539769f862e5e329d364c02bea9f8d26e5 Mon Sep 17 00:00:00 2001 From: Andy Thurman Date: Tue, 3 Sep 2024 09:48:45 +0100 Subject: [PATCH 2/4] Replace defaultProps with default params in SwipeRating.tsx --- src/SwipeRating.tsx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/SwipeRating.tsx b/src/SwipeRating.tsx index b658328..96cc63b 100644 --- a/src/SwipeRating.tsx +++ b/src/SwipeRating.tsx @@ -196,20 +196,22 @@ export default class SwipeRating extends Component< SwipeRatingProps, SwipeRatingState > { - static defaultProps = { - type: "star", - ratingImage: STAR_IMAGE, - ratingColor: "#f1c40f", - ratingBackgroundColor: "white", - ratingCount: 5, - showReadOnlyText: true, - imageSize: 40, - minValue: 0, - jumpValue: 0, - }; ratingRef: any; - constructor(props) { + constructor(overrideProps) { + const props = { + type: "star", + ratingImage: STAR_IMAGE, + ratingColor: "#f1c40f", + ratingBackgroundColor: "white", + ratingCount: 5, + showReadOnlyText: true, + imageSize: 40, + minValue: 0, + jumpValue: 0, + ...overrideProps + } + super(props); const { onStartRating, onSwipeRating, onFinishRating, fractions } = this.props; From 63c2c88b911d8aa26c6de267a531336e67224e9f Mon Sep 17 00:00:00 2001 From: Andy Thurman Date: Tue, 3 Sep 2024 09:52:24 +0100 Subject: [PATCH 3/4] Replace defaultProps with default params in TapRating.tsx amd remove defaultProps from Star.tsx --- src/TapRating.tsx | 26 ++++++++++++-------------- src/components/Star.tsx | 6 ------ 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/TapRating.tsx b/src/TapRating.tsx index ca010b7..be23a7b 100644 --- a/src/TapRating.tsx +++ b/src/TapRating.tsx @@ -109,18 +109,26 @@ export type TapRatingProps = { starStyle?: StyleProp; }; -const TapRating: React.FunctionComponent = (props) => { - const [position, setPosition] = useState(props.defaultRating); +const TapRating: React.FunctionComponent = + ({ + defaultRating = 3, + reviews = ["Terrible", "Bad", "Okay", "Good", "Great"], + count = 5, + showRating = true, + reviewColor = "rgba(230, 196, 46, 1)", + reviewSize = 25, + ...props + }) => { + const [position, setPosition] = useState(defaultRating); useEffect(() => { - const { defaultRating } = props; if (defaultRating === null || defaultRating === undefined) { setPosition(3); } else { setPosition(defaultRating); } - }, [props.defaultRating]); + }, [defaultRating]); const renderStars = (rating_array) => { return _.map(rating_array, (star) => { @@ -138,7 +146,6 @@ const TapRating: React.FunctionComponent = (props) => { setPosition(position); }; - const { count, reviews, showRating, reviewColor, reviewSize } = props; const rating_array = []; const starContainerStyle = [styles.starContainer]; @@ -183,15 +190,6 @@ const TapRating: React.FunctionComponent = (props) => { ); }; -TapRating.defaultProps = { - defaultRating: 3, - reviews: ["Terrible", "Bad", "Okay", "Good", "Great"], - count: 5, - showRating: true, - reviewColor: "rgba(230, 196, 46, 1)", - reviewSize: 25, -}; - const styles = StyleSheet.create({ ratingContainer: { backgroundColor: "transparent", diff --git a/src/components/Star.tsx b/src/components/Star.tsx index b451f98..b269d43 100644 --- a/src/components/Star.tsx +++ b/src/components/Star.tsx @@ -73,12 +73,6 @@ const Star: React.FunctionComponent = ({starImage = STAR_IMAGE, selec ); }; -Star.defaultProps = { - starImage: STAR_IMAGE, - selectedColor: "#f1c40f", - unSelectedColor: "#BDC3C7" -}; - export default Star; const styles = StyleSheet.create( { From 7c426d77cbccc596e18123af09ed39255fc40d65 Mon Sep 17 00:00:00 2001 From: Andy Thurman Date: Tue, 3 Sep 2024 10:31:02 +0100 Subject: [PATCH 4/4] rollback changes to SwipeRating as they do not cause warning --- src/SwipeRating.tsx | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/SwipeRating.tsx b/src/SwipeRating.tsx index 96cc63b..b658328 100644 --- a/src/SwipeRating.tsx +++ b/src/SwipeRating.tsx @@ -196,22 +196,20 @@ export default class SwipeRating extends Component< SwipeRatingProps, SwipeRatingState > { + static defaultProps = { + type: "star", + ratingImage: STAR_IMAGE, + ratingColor: "#f1c40f", + ratingBackgroundColor: "white", + ratingCount: 5, + showReadOnlyText: true, + imageSize: 40, + minValue: 0, + jumpValue: 0, + }; ratingRef: any; - constructor(overrideProps) { - const props = { - type: "star", - ratingImage: STAR_IMAGE, - ratingColor: "#f1c40f", - ratingBackgroundColor: "white", - ratingCount: 5, - showReadOnlyText: true, - imageSize: 40, - minValue: 0, - jumpValue: 0, - ...overrideProps - } - + constructor(props) { super(props); const { onStartRating, onSwipeRating, onFinishRating, fractions } = this.props;