Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
85 changes: 37 additions & 48 deletions src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<View
Expand All @@ -220,54 +256,7 @@ const ProgressBar = ({
{width ? (
<Animated.View
testID={`${testID}-fill`}
style={[
styles.progressBar,
{
width,
backgroundColor: tintColor,
transform: [
{
translateX: timer.interpolate(
indeterminate
? {
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,
],
}
: {
inputRange: [0, 1],
outputRange: [(isRTL ? 1 : -1) * 0.5 * width, 0],
}
),
},
{
// Workaround for workaround for https://github.com/facebook/react-native/issues/6278
scaleX: timer.interpolate(
indeterminate
? {
inputRange: [0, 0.5, 1],
outputRange: [
0.0001,
INDETERMINATE_MAX_WIDTH,
0.0001,
],
}
: {
inputRange: [0, 1],
outputRange: [0.0001, 1],
}
),
},
],
},
fillStyle,
]}
style={[styles.progressBar, progressBarStyle, fillStyle]}
/>
) : null}
</Animated.View>
Expand Down
15 changes: 15 additions & 0 deletions src/components/__tests__/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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(<ProgressBar progress={0.2} testID="progress-bar" />);
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);
});
15 changes: 3 additions & 12 deletions src/components/__tests__/__snapshots__/ProgressBar.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ exports[`renders colored progress bar 1`] = `
"flex": 1,
"transform": [
{
"translateX": -50,
},
{
"scaleX": 0.0001,
"translateX": -100,
},
],
"width": 100,
Expand Down Expand Up @@ -93,10 +90,7 @@ exports[`renders hidden progress bar 1`] = `
"flex": 1,
"transform": [
{
"translateX": -50,
},
{
"scaleX": 0.0001,
"translateX": -100,
},
],
"width": 100,
Expand Down Expand Up @@ -195,10 +189,7 @@ exports[`renders progress bar with specific progress 1`] = `
"flex": 1,
"transform": [
{
"translateX": -50,
},
{
"scaleX": 0.0001,
"translateX": -100,
},
],
"width": 100,
Expand Down