Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Use nativeDriver for color animations in RN >= 0.69
  • Loading branch information
antonis committed Apr 30, 2025
commit b05cb438d0b74f319870d22741f93f3958775d24
8 changes: 5 additions & 3 deletions packages/core/src/js/feedback/FeedbackWidgetManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { modalSheetContainer, modalWrapper, topSpacer } from './FeedbackWidget.s
import type { FeedbackWidgetStyles } from './FeedbackWidget.types';
import { getFeedbackOptions } from './integration';
import { lazyLoadAutoInjectFeedbackIntegration } from './lazy';
import { isModalSupported } from './utils';
import { isModalSupported, isNativeDriverSupportedForColorAnimations } from './utils';

const PULL_DOWN_CLOSE_THRESHOLD = 200;
const SLIDE_ANIMATION_DURATION = 200;
const BACKGROUND_ANIMATION_DURATION = 200;

const useNativeDriverForColorAnimations = isNativeDriverSupportedForColorAnimations();

class FeedbackWidgetManager {
private static _isVisible = false;
private static _setVisibility: (visible: boolean) => void;
Expand Down Expand Up @@ -124,7 +126,7 @@ class FeedbackWidgetProvider extends React.Component<FeedbackWidgetProviderProps
Animated.timing(this.state.backgroundOpacity, {
toValue: 1,
duration: BACKGROUND_ANIMATION_DURATION,
useNativeDriver: false,
useNativeDriver: useNativeDriverForColorAnimations,
easing: Easing.in(Easing.quad),
}),
Animated.timing(this.state.panY, {
Expand Down Expand Up @@ -206,7 +208,7 @@ class FeedbackWidgetProvider extends React.Component<FeedbackWidgetProviderProps
Animated.timing(this.state.backgroundOpacity, {
toValue: 0,
duration: BACKGROUND_ANIMATION_DURATION,
useNativeDriver: false,
useNativeDriver: useNativeDriverForColorAnimations,
easing: Easing.out(Easing.quad),
})
]).start(() => {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/js/feedback/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ export function isModalSupported(): boolean {
return !(isFabricEnabled() && major === 0 && minor < 71);
}

/**
* The native driver supports color animations since React Native 0.69.
* ref: https://github.com/facebook/react-native/commit/201f355479cafbcece3d9eb40a52bae003da3e5c
*/
export function isNativeDriverSupportedForColorAnimations(): boolean {
const { major, minor } = ReactNativeLibraries.ReactNativeVersion?.version || {};
return major >= 0 && minor >= 69;
}

export const isValidEmail = (email: string): boolean => {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
return emailRegex.test(email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { getDefaultTestClientOptions, TestClient } from '../mocks/client';

jest.mock('../../src/js/feedback/utils', () => ({
isModalSupported: jest.fn(),
isNativeDriverSupportedForColorAnimations: jest.fn().mockReturnValue(true),
}));

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