Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust progress bar wrapper height on web #3997

Merged
merged 2 commits into from
Aug 2, 2023
Merged
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
19 changes: 19 additions & 0 deletions example/src/Examples/ProgressBarExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,23 @@ const ProgressBarExample = () => {
<View style={styles.row}>
<Text variant="bodyMedium">ProgressBar with animated value</Text>
<AnimatedProgressBar
visible={visible}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

style={styles.progressBar}
animatedValue={progressBarValue}
theme={theme}
/>
</View>

<View style={[styles.row, styles.fullRow]}>
<Text variant="bodyMedium">
ProgressBar with custom percentage height
</Text>
<ProgressBar
style={styles.customPercentageHeight}
indeterminate
visible={visible}
/>
</View>
</ScreenWrapper>
);
};
Expand All @@ -112,9 +124,16 @@ const styles = StyleSheet.create({
row: {
marginVertical: 10,
},
fullRow: {
height: '100%',
width: '100%',
},
customHeight: {
height: 20,
},
customPercentageHeight: {
height: '50%',
},
progressBar: {
height: 15,
},
Expand Down
11 changes: 8 additions & 3 deletions src/components/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const ProgressBar = ({
animatedValue,
...rest
}: Props) => {
const isWeb = Platform.OS === 'web';
const theme = useInternalTheme(themeOverrides);
const { current: timer } = React.useRef<Animated.Value>(
new Animated.Value(0)
Expand Down Expand Up @@ -123,7 +124,7 @@ const ProgressBar = ({
duration: INDETERMINATE_DURATION,
toValue: 1,
// Animated.loop does not work if useNativeDriver is true on web
useNativeDriver: Platform.OS !== 'web',
useNativeDriver: !isWeb,
isInteraction: false,
});
}
Expand All @@ -140,7 +141,7 @@ const ProgressBar = ({
isInteraction: false,
}).start();
}
}, [fade, scale, indeterminate, timer, progress]);
}, [fade, scale, indeterminate, timer, progress, isWeb]);

const stopAnimation = React.useCallback(() => {
// Stop indeterminate animation
Expand Down Expand Up @@ -194,6 +195,7 @@ const ProgressBar = ({
accessibilityValue={
indeterminate ? {} : { min: 0, max: 100, now: progress * 100 }
}
style={isWeb && styles.webContainer}
>
<Animated.View
style={[
Expand Down Expand Up @@ -263,7 +265,10 @@ const styles = StyleSheet.create({
height: 4,
overflow: 'hidden',
},

webContainer: {
width: '100%',
height: '100%',
},
progressBar: {
flex: 1,
},
Expand Down
16 changes: 15 additions & 1 deletion src/components/__tests__/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { Animated } from 'react-native';
import { Animated, Platform } from 'react-native';

import { render, waitFor } from '@testing-library/react-native';

Expand All @@ -23,6 +23,10 @@ class ClassProgressBar extends React.Component<Props> {

const AnimatedProgressBar = Animated.createAnimatedComponent(ClassProgressBar);

afterEach(() => {
Platform.OS = 'ios';
});

it('renders progress bar with animated value', async () => {
const tree = render(<AnimatedProgressBar animatedValue={0.2} />);
await waitFor(() => tree.getByRole(a11yRole).props.onLayout(layoutEvent));
Expand Down Expand Up @@ -59,3 +63,13 @@ it('renders indeterminate progress bar', async () => {

expect(tree.toJSON()).toMatchSnapshot();
});

it('renders progress bar with full height on web', () => {
Platform.OS = 'web';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that affect every test from now on in this file?

const tree = render(<ProgressBar progress={0.2} />);

expect(tree.getByRole(a11yRole)).toHaveStyle({
width: '100%',
height: '100%',
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exports[`renders colored progress bar 1`] = `
}
accessible={true}
onLayout={[Function]}
style={false}
>
<View
collapsable={false}
Expand Down Expand Up @@ -68,6 +69,7 @@ exports[`renders hidden progress bar 1`] = `
}
accessible={true}
onLayout={[Function]}
style={false}
>
<View
collapsable={false}
Expand Down Expand Up @@ -113,6 +115,7 @@ exports[`renders indeterminate progress bar 1`] = `
accessibilityValue={Object {}}
accessible={true}
onLayout={[Function]}
style={false}
>
<View
collapsable={false}
Expand Down Expand Up @@ -164,6 +167,7 @@ exports[`renders progress bar with specific progress 1`] = `
}
accessible={true}
onLayout={[Function]}
style={false}
>
<View
collapsable={false}
Expand Down