Skip to content

Commit d62b286

Browse files
committed
Merge branch 'v7'
2 parents 36d123d + a25ee50 commit d62b286

19 files changed

Lines changed: 39660 additions & 17289 deletions

.eslintrc.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,39 @@
11
// This is a workaround for https://github.com/eslint/eslint/issues/3458
2-
require("@rushstack/eslint-patch/modern-module-resolution");
2+
require('@rushstack/eslint-patch/modern-module-resolution');
33

44
module.exports = {
5-
"root": true,
6-
"env": {
7-
"es2021": true,
8-
"node": true,
9-
"react-native/react-native": true // *2
5+
env: {
6+
es2021: true,
7+
node: true,
8+
'react-native/react-native': true // *2
109
},
11-
"extends": [
12-
"plugin:@typescript-eslint/recommended-requiring-type-checking", // *1
13-
"eslint-config-gev/react-native", // https://github.com/SrBrahma/eslint-config-gev
10+
extends: [
11+
'eslint-config-gev/js' // https://github.com/SrBrahma/eslint-config-gev
1412
],
15-
"parser": "@typescript-eslint/parser",
16-
"parserOptions": {
17-
"tsconfigRootDir": __dirname, // *1
18-
"project": ['./tsconfig.lint.json'], // *1
19-
"ecmaVersion": 12,
20-
"sourceType": "module",
21-
"ecmaFeatures": { // *2
22-
"jsx": true
13+
parser: '@typescript-eslint/parser',
14+
overrides: [ //* 3
15+
{
16+
files: ['*.ts', '*.tsx'],
17+
extends: [
18+
'plugin:@typescript-eslint/recommended-requiring-type-checking', // *1
19+
'eslint-config-gev/react-native' // https://github.com/SrBrahma/eslint-config-gev
20+
],
21+
parserOptions: {
22+
tsconfigRootDir: __dirname, // *1
23+
project: ['./tsconfig.lint.json'], // *1
24+
ecmaVersion: 12,
25+
sourceType: 'module',
26+
ecmaFeatures: { // *2
27+
jsx: true
28+
}
29+
},
2330
}
24-
},
25-
"ignorePatterns": [".eslintrc.js"],
26-
"rules": {
31+
],
32+
ignorePatterns: ['**/lib/**/*', '**/dist/**/*', '**/node_modules/**/*', '.eslintrc.js'],
33+
rules: {
2734
}
2835
};
2936

30-
// [*1]: https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md#getting-started---linting-with-type-information
31-
// [*2]: https://github.com/Intellicode/eslint-plugin-react-native#configuration
37+
// [*1] - https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md#getting-started---linting-with-type-information
38+
// [*2] - https://github.com/Intellicode/eslint-plugin-react-native#configuration
39+
// [*3] - https://stackoverflow.com/a/64488474

CHANGELOG.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,48 @@
1+
# 7.0.0 - 2022-07-26
2+
> Major changes to improve the performance, simplify the library usage and improve the Developer Experience. An important update that consolidates this library's maturity.
3+
4+
### Features
5+
* `stretch` property - [#7](https://github.com/SrBrahma/react-native-shadow-2/issues/7#issuecomment-899784537).
6+
* `disabled` property - Easy and performatic way to disable the shadow (but to keep rendering the children).
7+
* `containerViewProps` property.
8+
* `childrenViewProps` property.
9+
10+
### Changes
11+
* Renamed `viewStyle` to `style`.
12+
* Renamed `containerViewStyle` to `containerStyle`.
13+
* Renamed `finalColor` to `endColor`, to follow the `start/end` pattern of the following change.
14+
* `left`/`right` in `sides` and `corners` were changed to `start`/`end` for [RTL friendliness](https://reactnative.dev/blog/2016/08/19/right-to-left-support-for-react-native-apps)
15+
* `sides` and `corners` properties are now objects instead of arrays.
16+
> `sides` new type: `Record<'start' | 'end' | 'top' | 'bottom', boolean>`
17+
18+
> `corners` new type: `Record<'topStart' | 'topEnd' | 'bottomStart' | 'bottomEnd', boolean>`.
19+
20+
> Note that you may still use `borderTopLeftRadius` etc in `style` besides `borderTopStartRadius` if you want to.
21+
22+
### Removals
23+
<ul>
24+
<li><code>size</code> property. The size now can only be defined in the Shadow's or child's <code>style</code>'s <code>width</code> and <code>height</code> properties.</li>
25+
<li><code>radius</code> property. The radii now can only be defined in the Shadow's or child's <code>style</code>'s <code>borderRadius</code> related properties, such as <code>borderTopStartRadius</code>/<code>borderTopLeftRadius</code> etc.</li>
26+
<li>
27+
<details>
28+
<summary><code>getChildRadius</code> and <code>getViewStyleRadius</code>.</summary>
29+
Properties removed for the sake of simplicity of this package. Probably no one used them anyway. If you did use them and want or need them, open an issue about it with your use case. They are always active now. Before, they were active by default.
30+
</details>
31+
</li>
32+
</ul>
33+
34+
### Improvements
35+
* Significant performance and RAM usage due to general refactorings, SVGs' simplification (with the same appearence), improved memoizations and micro performance improvements.
36+
* Now using `colord` package instead of `polished` to deal with colors' alpha.
37+
38+
### Fixes
39+
* [RTL in web](https://github.com/necolas/react-native-web/issues/2350#issuecomment-1193642853).
40+
* Error when there is more than a child. [#38](https://github.com/SrBrahma/react-native-shadow-2/issues/38)
41+
* Error when there isn't a child. [#38 (comment)](https://github.com/SrBrahma/react-native-shadow-2/issues/38#issuecomment-1059716569)
42+
* Situational 1-pixel overlap of corners.
43+
44+
<br/><hr/><br/>
45+
146
## 6.0.6 - 2022-07-21
247
* Fixed Web Shadow when there are more than one being rendered. [#53](https://github.com/SrBrahma/react-native-shadow-2/issues/53). Many thanks, [@GreyJohnsonGit](https://github.com/GreyJohnsonGit)!
348

README.md

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,36 @@
1010

1111
# react-native-shadow-2
1212

13-
[react-native-shadow](https://github.com/879479119/react-native-shadow) is dead for years. This one is an improved version with more functionalities, Typescript support and written from scratch. It doesn't require the usage of the `size` property: the shadow is smartly applied on the first render and then precisely reapplied on the following renders.
13+
[react-native-shadow](https://github.com/879479119/react-native-shadow) is dead for years. This is an improved version with more functionalities, Typescript support and written from scratch. It's not required to define its size: the shadow is smartly applied on the first render and then precisely reapplied on the following ones.
1414

1515
It solves the old React Native issue of not having the same shadow appearence and usage for Android, iOS and Web.
1616

17-
The [ethercreative/react-native-shadow-generator](https://ethercreative.github.io/react-native-shadow-generator) website won't give you very similar results between the two platforms, for the reasons I described [here](https://github.com/ethercreative/react-native-shadow-generator/issues/2#issuecomment-738130722), when I started to think more seriously about this shadow issue.
17+
The [ethercreative/react-native-shadow-generator](https://ethercreative.github.io/react-native-shadow-generator) website won't give you very similar results between the two platforms, for the reasons I described [here](https://github.com/ethercreative/react-native-shadow-generator/issues/2#issuecomment-738130722). It's also not as customizable as this library.
1818

1919
Compatible with Android, iOS and Web. **And Expo!**
2020

21-
### [Read the FAQ below!](#️-faq)
21+
Supports [RTL](https://reactnative.dev/blog/2016/08/19/right-to-left-support-for-react-native-apps).
2222

23-
## [😍 Soon v7 will be released!](https://github.com/SrBrahma/react-native-shadow-2/blob/v7/CHANGELOG.md)
2423

25-
## [🍟 Demo / Expo Snack Sandbox](https://snack.expo.io/@srbrahma/react-native-shadow-2-sandbox)
2624

27-
## [📜 Changelog](https://github.com/SrBrahma/react-native-shadow-2/blob/main/CHANGELOG.md)
25+
### [🍟 Demo - Expo Snack Sandbox](https://snack.expo.io/@srbrahma/react-native-shadow-2-sandbox)
26+
> Give this library a quick try!
27+
28+
### [📰 7.0.0 Changelog - 2022-08-08](./CHANGELOG.md)
29+
> **There are important breaking changes! Read it if upgrading!**
30+
31+
### [↪️ Pre v7 Readme](https://github.com/SrBrahma/react-native-shadow-2/blob/36d123db4cf816d15ac5e3f9c9df8cff3e96bd2e/README.md)
32+
> Old Readme, if you are still using previous versions.
33+
34+
### [❗ Read the FAQ below!](#️-faq)
2835

2936
## 💿 Installation
3037

31-
### 1. First install [react-native-svg](https://github.com/react-native-svg/react-native-svg#installation).
38+
#### 1. First install [react-native-svg](https://github.com/react-native-svg/react-native-svg#installation).
3239

33-
### 2. Then install react-native-shadow-2:
40+
> The latest `react-native-svg` version is recommended, including if using Expo.
41+
42+
#### 2. Then install react-native-shadow-2:
3443

3544
```bash
3645
npm i react-native-shadow-2
@@ -54,8 +63,8 @@ import { Shadow } from 'react-native-shadow-2';
5463
<br/>
5564

5665
```tsx
57-
<Shadow distance={15} startColor={'#eb9066d8'} finalColor={'#ff00ff10'} offset={[3, 4]}>
58-
<View style={{ borderTopLeftRadius: 24, borderBottomRightRadius: 0, borderRadius: 10, backgroundColor: '#c454f0dd' }}>
66+
<Shadow distance={15} startColor={'#eb9066d8'} endColor={'#ff00ff10'} offset={[3, 4]}>
67+
<View style={{ borderTopStartRadius: 24, borderBottomEndRadius: 0, borderRadius: 10, backgroundColor: '#c454f0dd' }}>
5968
<Text style={{ margin: 20, fontSize: 20 }}>🤯</Text>
6069
</View>
6170
</Shadow>
@@ -66,38 +75,46 @@ import { Shadow } from 'react-native-shadow-2';
6675
## Properties
6776

6877
#### All properties are optional.
69-
70-
<!--$shadowProperties-->
71-
7278
| Property | Description | Type | Default
7379
| --- | --- | --- | ---
74-
| **startColor** | The color of the shadow when it's right next to the given content, leaving it. Accepts alpha channel. | `string` | `'#00000020'`
75-
| **finalColor** | The color of the shadow at the maximum distance from the content. Accepts alpha channel. | `string` | Transparent startColor. [Explanation](https://github.com/SrBrahma/react-native-shadow-2/issues/31#issuecomment-985578972)
80+
| **startColor** | The initial gradient color of the shadow. | `string` | `'#00000020'`
81+
| **endColor** | The final gradient color of the shadow. | `string` | Transparent startColor. [Explanation](https://github.com/SrBrahma/react-native-shadow-2/issues/31#issuecomment-985578972)
7682
| **distance** | How far the shadow goes. | `number` | `10`
77-
| **radius** | The radius of each corner of your child component. Passing a number will apply it to all corners.<br/><br/>If passing an object, `undefined` corners will have the radius of the `default` property if defined.<br/><br/>If `undefined`, it will try to get `viewStyle` radii if **`getViewStyleRadius`**, and then child's view style radii if **`getChildRadius`**, both true as default.<br/><br/>Each corner fallbacks to 0. | `number \| { default?: number ; topLeft?: number ; topRight?: number ; bottomLeft?: number ; bottomRight?: number }` | `undefined`
78-
| **offset** | Moves the shadow. Negative `x` moves it left, negative `y` moves it up.<br/><br/>Accepts `'x%'` values, in relation to the child's size.<br/><br/>Setting an offset will default `paintInside` to true, as it's usually the desired behaviour. | `[x: string \| number, y: string \| number]` | `[0, 0]`
79-
| **paintInside** | If the shadow should be applied inside the external shadows, below the child. `startColor` is used as fill color.<br/><br/>Useful when using `offset` or if your child has some transparency. | `boolean` | `false`, but `true` if `offset` is defined
80-
| **sides** | The sides that will have their shadows drawn. Doesn't include corners. | `("left" \| "right" \| "top" \| "bottom")[]` | `['left', 'right', 'top', 'bottom']`
81-
| **corners** | The corners that will have their shadows drawn. | `("topLeft" \| "topRight" \| "bottomLeft" \| "bottomRight")[]` | `['topLeft', 'topRight', 'bottomLeft', 'bottomRight']`
82-
| **size** | If you don't want the 2 renders of the shadow (1st applies the relative positioning and sizing that may contain a quick pixel gap, 2nd uses exact pixel size from onLayout), you may want to use this. Using this won't trigger the onLayout on 2nd render and beyond, as the values entered here are already precisely rounded and are equal to the onLayout values.<br/><br/>You may want to set `backgroundColor` in the `viewStyle` property for your child background color.<br/><br/>Useful for animations. | `[width: number, height: number]` | `undefined`
83-
| **safeRender** | If you don't want the relative sizing and positioning of the shadow on the 1st render but only on the 2nd render and beyond with the exact onLayout sizes. Useful if dealing with radii greater than the sides sizes, to avoid visual artifacts on the first render.<br/><br/>When `true`, the shadow only appears after the first render, where it's invisible. | `boolean` | `false`
84-
| **viewStyle** | The style of the view that wraps your child component.<br/><br/>If using the `size` property, this wrapping view will automatically receive as style the `size` values and the radiuses from the `radius` property or from the child, if `getChildRadius`. | `StyleProp<ViewStyle>` | `undefined`
85-
| **containerViewStyle** | The style of the view that contains the shadow and your child component. | `StyleProp<ViewStyle>` | `undefined`
86-
| **getChildRadius** | If it should try to get the radii from the child's view `style` if our `radius` property is `undefined`. It gets the values of each corner, like `borderTopLeftRadius` and `borderRadius` as fallback for all corners.<br/><br/>The corners defined in `viewStyle` have priority over child's view style, if **`getViewStyleRadius`**. | `boolean` | `true`
87-
| **getViewStyleRadius** | If it should try to get the radii from the `viewStyle` if `radius` property is `undefined`. It gets the values of each corner, like `borderTopLeftRadius` and `borderRadius` as fallback for all corners.<br/><br/>The corners defined in `viewStyle` have priority over child's view style, if **`getViewStyleRadius`**. | `boolean` | `true`
88-
89-
<!--/$shadowProperties-->
83+
| **offset** | Moves the shadow. Negative `x` moves it left/start, negative `y` moves it up.<br/><br/>Accepts `'x%'` values.<br/><br/>Defining this will default `paintInside` to **true**, as it's the usual desired behaviour. | `[x: string \| number, y: string \| number]` | `[0, 0]`
84+
| **paintInside** | Apply the shadow below/inside the content. `startColor` is used as fill color, without a gradient.<br/><br/>Useful when using `offset` or if your child has some transparency. | `boolean` | `false`, but `true` if `offset` is defined
85+
| **sides** | The sides that will have their shadows drawn. Doesn't include corners. Undefined sides fallbacks to **true**. | `Record<'left' \| 'right' \| 'top' \| 'bottom', boolean>` | `undefined`
86+
| **corners** | The corners that will have their shadows drawn. Undefined corners fallbacks to **true**. | `Record<'topStart' \| 'topEnd' \| 'bottomStart' \| 'bottomEnd', boolean>` | `undefined`
87+
| **style** | The style of the View that wraps your children. Read the note at the end. | `StyleProp<ViewStyle>` | `undefined`
88+
| **containerStyle** | The style of the View that wraps the Shadow and your children. Useful for margins. | `StyleProp<ViewStyle>` | `undefined`
89+
| **stretch** | Make your children ocuppy all available horizontal space. [Explanation](https://github.com/SrBrahma/react-native-shadow-2/issues/7#issuecomment-899784537). | `boolean` | `false`
90+
| **safeRender** | Won't use the relative sizing and positioning on the 1st render but on the following renders with the exact onLayout sizes. Useful if dealing with radii greater than the sides sizes (like a circle) to avoid visual artifacts on the 1st render.<br/><br/>If `true`, the Shadow doesn't appear on the 1st render. | `boolean` | `false`
91+
| **disabled** | Disables the Shadow. Useful for easily reusing components as sometimes shadows are not desired.<br/><br/>`containerStyle` and `style` are still applied. | `boolean` | `false`
92+
93+
## Notes
94+
95+
* If the Shadow has a single child, it will get the `width`, `height` and all of the `borderRadius` properties from the children's `style` property, if defined.
96+
97+
* You may also define those properties in the Shadow's `style`. The defined properties here will have priority over the ones defined in the child's `style`.
98+
99+
* If the `width` **and** `height` are defined in any of those, there will be only a single render, as the first automatic sizing won't happen, only the precise render.
100+
101+
* You can use either the `'borderTopLeftRadius'` or `'borderTopStartRadius'` and their variations to define the corners radii, although I recommend the latter as it's the RTL standard.
102+
103+
<!-- Seems hard to understand. Will leave it undoc'ed until I improve it. -->
104+
<!-- * We automatically set the radii in the `style` property, so it contains the Child's Android Ripple if you are using it. We already get those values, so it isn't an effort to set them. -->
90105

91106
## ⁉️ FAQ
92107

93108
**Q**: How to set the Shadow opacity?
94109

95-
**A**: The opacity is set directly in the `startColor` and `finalColor` properties, in the alpha channel. E.g.: `'#0001'` would be an almost transparent black. You may also use `'#rrggbbaa'`, `'rgba()'`, `'hsla()'` etc. [All patterns in this link, but not int colors, are accepted](https://reactnative.dev/docs/colors).
110+
**A**: The opacity is set directly in the `startColor` and `endColor` properties, in the alpha channel. E.g.: `'#0001'` would be an almost transparent black. You may also use `'#rrggbbaa'`, `'rgba()'`, `'hsla()'` etc. [All patterns in this link, but not int colors, are accepted](https://reactnative.dev/docs/colors).
111+
112+
You may also use the `opacity` style to change both.
96113

97114

98115
**Q**: [My component is no longer using the available parent width after applying the Shadow! What to do?](https://github.com/SrBrahma/react-native-shadow-2/issues/7#issuecomment-899764882)
99116

100-
**A**: Use `viewStyle={{alignSelf: 'stretch'}}` in your Shadow component. Explanation in link above!
117+
**A**: Use the `stretch` property or `style={{alignSelf: 'stretch'}}` in your Shadow component. Explanation in link above!
101118

102119

103120
**Q**: I want a preset for my Shadows!
@@ -117,11 +134,18 @@ const ShadowPresets = {
117134

118135
**A**: Upgrade your Typescript to at least 4.0.0! Those two properties use [**labeled tuples**](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#labeled-tuple-elements). If you don't use Typescript, this won't happen.
119136

137+
138+
## Performance Guide
139+
140+
> While you usually won't have any performance issues by using this, you may have performance issues if you have many Shadows in your screen, like in a FlatList. Those may help you to improve your performance:
141+
142+
* In `style` and on child's `style`, avoid using inline styles (eg `{{flex: 1}}`). Prefer using styles from `StyleSheet.create`. If you are using arrays for the styles (eg `style={[styles.view, {flex: 1}]}`), have this array creation outside the component or inside an `useMemo`, so it isn't unnecessarily created a new reference at each render and we can better memoize the Shadow.
143+
120144
## 🐛 Notes / Known Issues
121145

122146
* [Setting (or obtaining from the child) a too high `radius` (`> size/2`) will mess the shadow.](https://github.com/SrBrahma/react-native-shadow-2/issues/15)
123147
**Update v5:** The radius is now properly limited on the 2nd render and beyond! You may use the safeRender to don't render the shadow until this 2nd render, when the onLayout happens and we get the exact sizes to apply this limit.
124148

125149
## 📰 Popularly seen on
126150
### [LogRocket - Applying box shadows in React Native](https://blog.logrocket.com/applying-box-shadows-in-react-native/)
127-
### [V. Petrachin - Top 10 Libraries You Should Know for React Native in 2022](https://viniciuspetrachin.medium.com/top-10-libraries-you-should-know-for-react-native-d435e5209c96)
151+
### [V. Petrachin - Top 10 Libraries You Should Know for React Native in 2022](https://viniciuspetrachin.medium.com/top-10-libraries-you-should-know-for-react-native-d435e5209c96)

0 commit comments

Comments
 (0)