Skip to content

Commit abf9b87

Browse files
authored
fix: setNativeProps not supported on web (#2620)
1 parent 1cffa66 commit abf9b87

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

src/components/KeyboardAwareScrollView/KeyboardAwareBase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class KeyboardAwareBase extends Component {
5555
componentDidMount() {
5656
if (this._keyboardAwareView && this.props.startScrolledToBottom) {
5757
this.scrollToBottom(false);
58-
setTimeout(() => this._keyboardAwareView.setNativeProps({opacity: 1}), 100);
58+
setTimeout(() => this._keyboardAwareView.setNativeProps?.({opacity: 1}), 100);
5959
}
6060
}
6161

src/components/panningViews/panDismissibleView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class PanDismissibleView extends PureComponent<Props, State> {
198198

199199
setNativeProps = (left: number, top: number) => {
200200
if (this.ref.current) {
201-
this.ref.current.setNativeProps({style: {left, top}});
201+
this.ref.current?.setNativeProps?.({style: {left, top}});
202202
this.left = left;
203203
this.top = top;
204204
}

src/components/panningViews/panResponderView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class PanResponderView extends PureComponent<Props> {
8888

8989
setNativeProps(left: number, top: number) {
9090
if (this.ref.current) {
91-
this.ref.current.setNativeProps({style: {left, top}});
91+
this.ref.current?.setNativeProps?.({style: {left, top}});
9292
this.left = left;
9393
this.top = top;
9494
}

src/components/slider/Thumb.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ const Thumb = forwardRef((props: ThumbProps, ref: any) => {
8787
const style = thumbStyle || styles.thumb;
8888
const activeStyle = activeThumbStyle || styles.activeThumb;
8989
const activeOrInactiveStyle = !disabled ? (start ? activeStyle : style) : {};
90-
90+
9191
thumbStyles.style = _.omit(activeOrInactiveStyle, 'height', 'width');
9292
//@ts-expect-error
93-
thumbRef.current?.setNativeProps(thumbStyles);
93+
thumbRef.current?.setNativeProps?.(thumbStyles);
9494

9595
scaleThumb(start);
9696
}

src/components/slider/index.tsx

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export type SliderProps = Omit<ThumbProps, 'ref'> & {
8282
*/
8383
onSeekEnd?: () => void;
8484
/**
85-
* Callback that notifies when the reset function was invoked
85+
* Callback that notifies when the reset function was invoked
8686
*/
8787
onReset?: () => void;
8888
/**
@@ -121,7 +121,7 @@ export type SliderProps = Omit<ThumbProps, 'ref'> & {
121121
* The slider's test identifier
122122
*/
123123
testID?: string;
124-
/**
124+
/**
125125
* Whether to use the new Slider implementation using Reanimated
126126
*/
127127
migrate?: boolean;
@@ -169,10 +169,10 @@ export default class Slider extends PureComponent<SliderProps, State> {
169169
private minThumb = React.createRef<RNView>();
170170
private activeThumbRef: React.RefObject<RNView>;
171171
private panResponder;
172-
172+
173173
private minTrack = React.createRef<RNView>();
174174
private _minTrackStyles: MinTrackStyle = {};
175-
175+
176176
private _x = 0;
177177
private _x_min = 0;
178178
private lastDx = 0;
@@ -270,18 +270,18 @@ export default class Slider extends PureComponent<SliderProps, State> {
270270

271271
componentDidUpdate(prevProps: SliderProps, prevState: State) {
272272
const {useRange, value, initialMinimumValue} = this.props;
273-
273+
274274
if (!useRange && prevProps.value !== value) {
275275
this.initialValue = this.getRoundedValue(value);
276-
276+
277277
// set position for new value
278278
this._x = this.getXForValue(this.initialValue);
279279
this.moveTo(this._x);
280280
}
281281

282282
if (prevState.measureCompleted !== this.state.measureCompleted) {
283283
this.initialThumbSize = this.state.thumbSize; // for thumb enlargement
284-
284+
285285
// set initial position
286286
this._x = this.getXForValue(this.initialValue);
287287
this._x_min = this.getXForValue(this.minInitialValue);
@@ -395,16 +395,16 @@ export default class Slider extends PureComponent<SliderProps, State> {
395395
const nonOverlappingTrackWidth = trackSize.width - this.initialThumbSize.width;
396396
const _x = this.shouldForceLTR ? trackSize.width - x : x; // adjust for RTL
397397
const left = trackSize.width === 0 ? _x : (_x * nonOverlappingTrackWidth) / trackSize.width; // do not render above prefix\suffix icon\text
398-
398+
399399
if (useRange) {
400400
const minThumbPosition = this._minThumbStyles?.left as number;
401-
if (useGap && left > minThumbPosition + thumbSize.width + MIN_RANGE_GAP
401+
if (useGap && left > minThumbPosition + thumbSize.width + MIN_RANGE_GAP
402402
|| !useGap && left >= minThumbPosition) {
403403
this._thumbStyles.left = left;
404-
404+
405405
const width = left - minThumbPosition;
406406
this._minTrackStyles.width = width;
407-
407+
408408
if (this.didMount) {
409409
this.updateValue(x);
410410
}
@@ -413,9 +413,9 @@ export default class Slider extends PureComponent<SliderProps, State> {
413413
this._thumbStyles.left = left;
414414
this._minTrackStyles.width = Math.min(trackSize.width, x);
415415
}
416-
417-
this.thumb.current.setNativeProps(this._thumbStyles);
418-
this.minTrack.current?.setNativeProps(this._minTrackStyles);
416+
417+
this.thumb.current?.setNativeProps?.(this._thumbStyles);
418+
this.minTrack.current?.setNativeProps?.(this._minTrackStyles);
419419
}
420420
} else {
421421
this.moveMinTo(x);
@@ -430,18 +430,18 @@ export default class Slider extends PureComponent<SliderProps, State> {
430430
const nonOverlappingTrackWidth = trackSize.width - this.initialThumbSize.width;
431431
const _x = this.shouldForceLTR ? nonOverlappingTrackWidth - x : x; // adjust for RTL
432432
const left = trackSize.width === 0 ? _x : (_x * nonOverlappingTrackWidth) / trackSize.width; // do not render above prefix\suffix icon\text
433-
433+
434434
const maxThumbPosition = this._thumbStyles?.left as number;
435-
if (useGap && left < maxThumbPosition - thumbSize.width - MIN_RANGE_GAP
435+
if (useGap && left < maxThumbPosition - thumbSize.width - MIN_RANGE_GAP
436436
|| !useGap && left <= maxThumbPosition) {
437437
this._minThumbStyles.left = left;
438-
438+
439439
this._minTrackStyles.width = maxThumbPosition - x;
440440
this._minTrackStyles.left = x;
441-
442-
this.minThumb.current?.setNativeProps(this._minThumbStyles);
443-
this.minTrack.current?.setNativeProps(this._minTrackStyles);
444-
441+
442+
this.minThumb.current?.setNativeProps?.(this._minThumbStyles);
443+
this.minTrack.current?.setNativeProps?.(this._minTrackStyles);
444+
445445
if (this.didMount) {
446446
this.updateValue(x);
447447
}
@@ -464,9 +464,9 @@ export default class Slider extends PureComponent<SliderProps, State> {
464464
this.setActiveThumb(this.thumb);
465465
}
466466
}
467-
467+
468468
this.set_x(newX);
469-
469+
470470
if (!useRange) {
471471
this.updateValue(this.get_x());
472472
}
@@ -550,7 +550,7 @@ export default class Slider extends PureComponent<SliderProps, State> {
550550
}
551551

552552
let values = {min: this.lastMinValue, max: this.lastValue};
553-
553+
554554
if (Constants.isRTL && this.props.disableRTL) { // forceRTL for range slider
555555
const {maximumValue} = this.props;
556556
values = {min: maximumValue - this.lastValue, max: maximumValue - this.lastMinValue};
@@ -749,7 +749,7 @@ export default class Slider extends PureComponent<SliderProps, State> {
749749
if (migrate) {
750750
return <IncubatorSlider {...this.props}/>;
751751
}
752-
752+
753753
return (
754754
<View
755755
style={[styles.container, containerStyle]}

src/components/tabController/TabBarItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default function TabBarItem({
159159
if (!itemWidth.current && itemRef?.current) {
160160
itemWidth.current = width;
161161
// @ts-ignore
162-
itemRef.current?.setNativeProps({style: {width, paddingHorizontal: null, flex: null}});
162+
itemRef.current?.setNativeProps?.({style: {width, paddingHorizontal: null, flex: null}});
163163
props.onLayout?.(event, index);
164164
}
165165
},

0 commit comments

Comments
 (0)