Skip to content

Commit 6d08c6d

Browse files
authored
feat: add customizable gradient props to Shimmer component (#1)
authored by: Alex Zamfir <alex.zamfir@callstack.com>
1 parent 4fe2acf commit 6d08c6d

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ export default function App() {
2323
}
2424
```
2525

26+
## Props
27+
28+
#### `Shimmer` Component
29+
30+
| Prop | Type | Default | Description |
31+
|-------------------|------------------------------------|----------------------------------------------|----------------------------------------------------|
32+
| `style` | `ViewStyle` or `ViewStyle[]` | `undefined` | Custom styles for the Shimmer container. |
33+
| `linearGradients` | `string[]` | `['transparent', '#FFFFFF30', 'transparent']` | Array of colors for the linear gradient animation. |
34+
| `gradientStart` | `{ x: number; y: number }` | `{ x: 0, y: 0.5 }` | Start coordinates for the linear gradient. |
35+
| `gradientEnd` | `{ x: number; y: number }` | `{ x: 1, y: 0.5 }` | End coordinates for the linear gradient. |
36+
2637
## Contributing
2738

2839
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

src/Shimmer.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ import Animated, { useAnimatedStyle } from 'react-native-reanimated';
44
import { ShimmerContext } from './ShimmerContext';
55
import { MyLinearGradient } from './LinearGradient';
66

7+
const DEFAULT_LINEAR_GRADIENTS = ['transparent', '#FFFFFF30', 'transparent'];
8+
const DEFAULT_GRADIENT_START = { x: 0, y: 0.5 };
9+
const DEFAULT_GRADIENT_END = { x: 1, y: 0.5 };
10+
711
interface Props {
812
style?: ViewStyle | ViewStyle[];
13+
linearGradients?: string[];
14+
gradientStart?: { x: number; y: number };
15+
gradientEnd?: { x: number; y: number };
916
}
1017

11-
export const Shimmer: React.FC<Props> = ({ style }) => {
18+
export const Shimmer = ({
19+
style,
20+
linearGradients = DEFAULT_LINEAR_GRADIENTS,
21+
gradientStart = DEFAULT_GRADIENT_START,
22+
gradientEnd = DEFAULT_GRADIENT_END,
23+
}: Props): React.ReactNode => {
1224
const shimmer = useContext(ShimmerContext);
1325
const shimmerRef = React.useRef<View>(null);
1426
const [offset, setOffset] = useState(0);
@@ -39,9 +51,9 @@ export const Shimmer: React.FC<Props> = ({ style }) => {
3951
<View ref={shimmerRef} onLayout={measure} style={[styles.container, style]}>
4052
<Animated.View style={[gradientStyle, styles.gradientWrapper]}>
4153
<MyLinearGradient
42-
colors={['transparent', '#FFFFFF30', 'transparent']}
43-
start={{ x: 0, y: 0.5 }}
44-
end={{ x: 1, y: 0.5 }}
54+
colors={linearGradients}
55+
start={gradientStart}
56+
end={gradientEnd}
4557
style={StyleSheet.absoluteFill}
4658
/>
4759
</Animated.View>

0 commit comments

Comments
 (0)