Skip to content

Commit 418fae9

Browse files
authored
Enabling backgroundOpacity and foregroundOpacity for ContentLoader in React Native environment (#324)
* Update `IContentLoaderProps` in index.ts Extended `IcontentLoaderProps` with props `backgroundOpacity` and `foregroundOpacity`. * Update NativeSvg fore back/foregroundOpacity Svg.tsx Added `backgroundOpacity` and `foregroundOpacity` freature for Native. * Enabling `backgroundOpacity` and `foregroundOpacity` for `ContentLoader` on Native. in README.md Updated docs to describe `backgourndOpacity` and `foregroundOpacity` props of `ContentLoader` available in React Native environment.
1 parent c73be7a commit 418fae9

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ const MyLoader = () => (
119119
| **`rtl?: boolean`** <br /> Defaults to `false` | React DOM<br/>React Native | Content right-to-left. |
120120
| **`backgroundColor?: string`** <br /> Defaults to `#f5f6f7` | React DOM<br/>React Native | Used as background of animation. |
121121
| **`foregroundColor?: string`** <br /> Defaults to `#eee` | React DOM<br/>React Native | Used as the foreground of animation. |
122-
| **`backgroundOpacity?: number`** <br /> Defaults to `1` | React DOM only | Background opacity (0 = transparent, 1 = opaque)<br/>used to solve an issue in [Safari](#safari--ios) |
123-
| **`foregroundOpacity?: number`** <br /> Defaults to `1` | React DOM only | Animation opacity (0 = transparent, 1 = opaque)<br/>used to solve an issue in [Safari](#safari--ios) |
122+
| **`backgroundOpacity?: number`** <br /> Defaults to `1` | React DOM<br/>React Native | Background opacity (0 = transparent, 1 = opaque)<br/>used to solve an issue in [Safari](#safari--ios) |
123+
| **`foregroundOpacity?: number`** <br /> Defaults to `1` | React DOM<br/>React Native | Animation opacity (0 = transparent, 1 = opaque)<br/>used to solve an issue in [Safari](#safari--ios) |
124124
| **`style?: React.CSSProperties`** <br /> Defaults to `{}` | React DOM only | |
125125
| **`uniqueKey?: string`** <br /> Defaults to random unique id | React DOM only | Use the same value of prop key, <br/>that will solve inconsistency on the SSR, see more [here](https://github.com/danilowoz/react-content-loader/issues/78). |
126126
| **`beforeMask?: JSX.Element`** <br /> Defaults to null | React DOM<br/>React Native | Define custom shapes before content, <br/>see more [here](https://github.com/danilowoz/react-content-loader/issues/266). |

Diff for: src/native/Svg.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class NativeSvg extends Component<IContentLoaderProps> {
1717
static defaultProps = {
1818
animate: true,
1919
backgroundColor: '#f5f6f7',
20+
backgroundOpacity: 1,
2021
foregroundColor: '#eee',
22+
foregroundOpacity: 1,
2123
rtl: false,
2224
speed: 1.2,
2325
interval: 0.25,
@@ -74,7 +76,9 @@ class NativeSvg extends Component<IContentLoaderProps> {
7476
const {
7577
children,
7678
backgroundColor,
79+
backgroundOpacity,
7780
foregroundColor,
81+
foregroundOpacity,
7882
rtl,
7983
style,
8084
beforeMask,
@@ -124,9 +128,9 @@ class NativeSvg extends Component<IContentLoaderProps> {
124128
y1={0}
125129
y2={0}
126130
>
127-
<Stop offset={0} stopColor={backgroundColor} />
128-
<Stop offset={0.5} stopColor={foregroundColor} />
129-
<Stop offset={1} stopColor={backgroundColor} />
131+
<Stop offset={0} stopColor={backgroundColor} stopOpacity={backgroundOpacity} />
132+
<Stop offset={0.5} stopColor={foregroundColor} stopOpacity={foregroundOpacity} />
133+
<Stop offset={1} stopColor={backgroundColor} stopOpacity={backgroundOpacity} />
130134
</AnimatedLinearGradient>
131135
</Defs>
132136
</Svg>

Diff for: src/native/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import ContentLoader from './ContentLoader'
55
export interface IContentLoaderProps extends SvgProps {
66
animate?: boolean
77
backgroundColor?: string
8+
backgroundOpacity?: number
89
foregroundColor?: string
10+
foregroundOpacity?: number
911
rtl?: boolean
1012
speed?: number
1113
interval?: number

0 commit comments

Comments
 (0)