diff --git a/src/components/ProgressBar.tsx b/src/components/ProgressBar.tsx index 790204f4f8..f3cfddd8f4 100644 --- a/src/components/ProgressBar.tsx +++ b/src/components/ProgressBar.tsx @@ -194,6 +194,42 @@ const ProgressBar = ({ const trackTintColor = theme.isV3 ? theme.colors.surfaceVariant : setColor(tintColor).alpha(0.38).rgb().string(); + const progressBarStyle = indeterminate + ? { + width, + backgroundColor: tintColor, + transform: [ + { + translateX: timer.interpolate({ + inputRange: [0, 0.5, 1], + outputRange: [ + (isRTL ? 1 : -1) * 0.5 * width, + (isRTL ? 1 : -1) * 0.5 * INDETERMINATE_MAX_WIDTH * width, + (isRTL ? -1 : 1) * 0.7 * width, + ], + }), + }, + { + // Workaround for workaround for https://github.com/facebook/react-native/issues/6278 + scaleX: timer.interpolate({ + inputRange: [0, 0.5, 1], + outputRange: [0.0001, INDETERMINATE_MAX_WIDTH, 0.0001], + }), + }, + ], + } + : { + width, + backgroundColor: tintColor, + transform: [ + { + translateX: timer.interpolate({ + inputRange: [0, 1], + outputRange: [(isRTL ? 1 : -1) * width, 0], + }), + }, + ], + }; return ( ) : null} diff --git a/src/components/__tests__/ProgressBar.test.tsx b/src/components/__tests__/ProgressBar.test.tsx index 9aac20ac91..4df7d6fcc8 100644 --- a/src/components/__tests__/ProgressBar.test.tsx +++ b/src/components/__tests__/ProgressBar.test.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import { Animated, Platform, StyleSheet } from 'react-native'; +import type { ViewStyle } from 'react-native'; import { act, render } from '@testing-library/react-native'; @@ -97,3 +98,17 @@ it('renders progress bar with custom style of filled part', async () => { borderRadius: 4, }); }); + +it('does not scale the determinate fill width', async () => { + const tree = render(); + await triggerLayout(tree); + + const fillStyle = StyleSheet.flatten( + tree.getByTestId('progress-bar-fill').props.style + ) as ViewStyle; + const transform = fillStyle.transform; + + expect( + Array.isArray(transform) && transform.some((value) => 'scaleX' in value) + ).toBe(false); +}); diff --git a/src/components/__tests__/__snapshots__/ProgressBar.test.tsx.snap b/src/components/__tests__/__snapshots__/ProgressBar.test.tsx.snap index ae5c19ff75..4dd51aa570 100644 --- a/src/components/__tests__/__snapshots__/ProgressBar.test.tsx.snap +++ b/src/components/__tests__/__snapshots__/ProgressBar.test.tsx.snap @@ -39,10 +39,7 @@ exports[`renders colored progress bar 1`] = ` "flex": 1, "transform": [ { - "translateX": -50, - }, - { - "scaleX": 0.0001, + "translateX": -100, }, ], "width": 100, @@ -93,10 +90,7 @@ exports[`renders hidden progress bar 1`] = ` "flex": 1, "transform": [ { - "translateX": -50, - }, - { - "scaleX": 0.0001, + "translateX": -100, }, ], "width": 100, @@ -195,10 +189,7 @@ exports[`renders progress bar with specific progress 1`] = ` "flex": 1, "transform": [ { - "translateX": -50, - }, - { - "scaleX": 0.0001, + "translateX": -100, }, ], "width": 100,