Skip to content

Commit b05cb43

Browse files
committed
Use nativeDriver for color animations in RN >= 0.69
1 parent 0eb22ef commit b05cb43

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

packages/core/src/js/feedback/FeedbackWidgetManager.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import { modalSheetContainer, modalWrapper, topSpacer } from './FeedbackWidget.s
99
import type { FeedbackWidgetStyles } from './FeedbackWidget.types';
1010
import { getFeedbackOptions } from './integration';
1111
import { lazyLoadAutoInjectFeedbackIntegration } from './lazy';
12-
import { isModalSupported } from './utils';
12+
import { isModalSupported, isNativeDriverSupportedForColorAnimations } from './utils';
1313

1414
const PULL_DOWN_CLOSE_THRESHOLD = 200;
1515
const SLIDE_ANIMATION_DURATION = 200;
1616
const BACKGROUND_ANIMATION_DURATION = 200;
1717

18+
const useNativeDriverForColorAnimations = isNativeDriverSupportedForColorAnimations();
19+
1820
class FeedbackWidgetManager {
1921
private static _isVisible = false;
2022
private static _setVisibility: (visible: boolean) => void;
@@ -124,7 +126,7 @@ class FeedbackWidgetProvider extends React.Component<FeedbackWidgetProviderProps
124126
Animated.timing(this.state.backgroundOpacity, {
125127
toValue: 1,
126128
duration: BACKGROUND_ANIMATION_DURATION,
127-
useNativeDriver: false,
129+
useNativeDriver: useNativeDriverForColorAnimations,
128130
easing: Easing.in(Easing.quad),
129131
}),
130132
Animated.timing(this.state.panY, {
@@ -206,7 +208,7 @@ class FeedbackWidgetProvider extends React.Component<FeedbackWidgetProviderProps
206208
Animated.timing(this.state.backgroundOpacity, {
207209
toValue: 0,
208210
duration: BACKGROUND_ANIMATION_DURATION,
209-
useNativeDriver: false,
211+
useNativeDriver: useNativeDriverForColorAnimations,
210212
easing: Easing.out(Easing.quad),
211213
})
212214
]).start(() => {

packages/core/src/js/feedback/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ export function isModalSupported(): boolean {
1818
return !(isFabricEnabled() && major === 0 && minor < 71);
1919
}
2020

21+
/**
22+
* The native driver supports color animations since React Native 0.69.
23+
* ref: https://github.com/facebook/react-native/commit/201f355479cafbcece3d9eb40a52bae003da3e5c
24+
*/
25+
export function isNativeDriverSupportedForColorAnimations(): boolean {
26+
const { major, minor } = ReactNativeLibraries.ReactNativeVersion?.version || {};
27+
return major >= 0 && minor >= 69;
28+
}
29+
2130
export const isValidEmail = (email: string): boolean => {
2231
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
2332
return emailRegex.test(email);

packages/core/test/feedback/FeedbackWidgetManager.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { getDefaultTestClientOptions, TestClient } from '../mocks/client';
1212

1313
jest.mock('../../src/js/feedback/utils', () => ({
1414
isModalSupported: jest.fn(),
15+
isNativeDriverSupportedForColorAnimations: jest.fn().mockReturnValue(true),
1516
}));
1617

1718
const consoleWarnSpy = jest.spyOn(console, 'warn');

0 commit comments

Comments
 (0)