Skip to content
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export default function App() {
}
```

## Props

#### `Shimmer` Component

| Prop | Type | Default | Description |
|-------------------|------------------------------------|----------------------------------------------|----------------------------------------------------|
| `style` | `ViewStyle` or `ViewStyle[]` | `undefined` | Custom styles for the Shimmer container. |
| `linearGradients` | `string[]` | `['transparent', '#FFFFFF30', 'transparent']` | Array of colors for the linear gradient animation. |
| `gradientStart` | `{ x: number; y: number }` | `{ x: 0, y: 0.5 }` | Start coordinates for the linear gradient. |
| `gradientEnd` | `{ x: number; y: number }` | `{ x: 1, y: 0.5 }` | End coordinates for the linear gradient. |

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
Expand Down
20 changes: 16 additions & 4 deletions src/Shimmer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,23 @@ import Animated, { useAnimatedStyle } from 'react-native-reanimated';
import { ShimmerContext } from './ShimmerContext';
import { MyLinearGradient } from './LinearGradient';

const DEFAULT_LINEAR_GRADIENTS = ['transparent', '#FFFFFF30', 'transparent'];
const DEFAULT_GRADIENT_START = { x: 0, y: 0.5 };
const DEFAULT_GRADIENT_END = { x: 1, y: 0.5 };

interface Props {
style?: ViewStyle | ViewStyle[];
linearGradients?: string[];
gradientStart?: { x: number; y: number };
gradientEnd?: { x: number; y: number };
}

export const Shimmer: React.FC<Props> = ({ style }) => {
export const Shimmer = ({
style,
linearGradients = DEFAULT_LINEAR_GRADIENTS,
gradientStart = DEFAULT_GRADIENT_START,
gradientEnd = DEFAULT_GRADIENT_END,
}: Props): React.ReactNode => {
const shimmer = useContext(ShimmerContext);
const shimmerRef = React.useRef<View>(null);
const [offset, setOffset] = useState(0);
Expand Down Expand Up @@ -39,9 +51,9 @@ export const Shimmer: React.FC<Props> = ({ style }) => {
<View ref={shimmerRef} onLayout={measure} style={[styles.container, style]}>
<Animated.View style={[gradientStyle, styles.gradientWrapper]}>
<MyLinearGradient
colors={['transparent', '#FFFFFF30', 'transparent']}
start={{ x: 0, y: 0.5 }}
end={{ x: 1, y: 0.5 }}
colors={linearGradients}
start={gradientStart}
end={gradientEnd}
style={StyleSheet.absoluteFill}
/>
</Animated.View>
Expand Down