Skip to content

Commit

Permalink
Migrate usages of @react-native-community/art to react-native-svg (#229)
Browse files Browse the repository at this point in the history
* Migrate usages of @react-native-community/art to react-native-svg

* Update Circle.js

* Update Sector.js

* Update package.json

* Update pods lockfile and react-native-svg as a dev dependency

* Fix bug with incorrect rotation

* Change remaining occurence of ReactART in README.md

Co-authored-by: Joel Arvidsson <[email protected]>
  • Loading branch information
frw and oblador authored Jul 10, 2021
1 parent 8206718 commit afd3d70
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 61 deletions.
29 changes: 15 additions & 14 deletions Circle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Animated, StyleSheet, Text, View } from 'react-native';
import { Surface as ARTSurface } from '@react-native-community/art';
import { Svg } from 'react-native-svg';

import Arc from './Shapes/Arc';
import withAnimation from './withAnimation';

const CIRCLE = Math.PI * 2;

const AnimatedSurface = Animated.createAnimatedComponent(ARTSurface);
const AnimatedSvg = Animated.createAnimatedComponent(Svg);
const AnimatedArc = Animated.createAnimatedComponent(Arc);

const styles = StyleSheet.create({
Expand Down Expand Up @@ -110,7 +110,7 @@ export class ProgressCircle extends Component {
const textOffset = border + thickness;
const textSize = size - textOffset * 2;

const Surface = rotation ? AnimatedSurface : ARTSurface;
const Surface = rotation ? AnimatedSvg : Svg;
const Shape = animated ? AnimatedArc : Arc;
const progressValue = animated ? this.progressValue : progress;
const angle = animated
Expand All @@ -122,19 +122,20 @@ export class ProgressCircle extends Component {
<Surface
width={size}
height={size}
style={{
transform: [
{
rotate:
indeterminate && rotation
? rotation.interpolate({
style={
indeterminate && rotation
? {
transform: [
{
rotate: rotation.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg'],
})
: '0deg',
},
],
}}
}),
},
],
}
: undefined
}
>
{unfilledColor && progressValue !== 1 ? (
<Shape
Expand Down
6 changes: 3 additions & 3 deletions CircleSnail.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Animated, Easing } from 'react-native';
import { Surface as ARTSurface } from '@react-native-community/art';
import { Svg } from 'react-native-svg';

import Arc from './Shapes/Arc';

Expand Down Expand Up @@ -163,7 +163,7 @@ export default class CircleSnail extends Component {
},
]}
>
<ARTSurface width={size} height={size}>
<Svg width={size} height={size}>
<AnimatedArc
direction={
direction === 'counter-clockwise'
Expand All @@ -178,7 +178,7 @@ export default class CircleSnail extends Component {
strokeCap={strokeCap}
strokeWidth={thickness}
/>
</ARTSurface>
</Svg>
{children}
</Animated.View>
);
Expand Down
10 changes: 5 additions & 5 deletions Example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ PODS:
- React-cxxreact (= 0.64.2)
- React-jsi (= 0.64.2)
- React-perflogger (= 0.64.2)
- ReactNativeART (1.2.0):
- RNSVG (12.1.1):
- React
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -371,7 +371,7 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "ReactNativeART (from `../node_modules/@react-native-community/art`)"
- RNSVG (from `../node_modules/react-native-svg`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand Down Expand Up @@ -444,8 +444,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/runtimeexecutor"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
ReactNativeART:
:path: "../node_modules/@react-native-community/art"
RNSVG:
:path: "../node_modules/react-native-svg"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

Expand Down Expand Up @@ -488,7 +488,7 @@ SPEC CHECKSUMS:
React-RCTVibration: 24600e3b1aaa77126989bc58b6747509a1ba14f3
React-runtimeexecutor: a9904c6d0218fb9f8b19d6dd88607225927668f9
ReactCommon: 149906e01aa51142707a10665185db879898e966
ReactNativeART: 78edc68dd4a1e675338cd0cd113319cf3a65f2ab
RNSVG: 551acb6562324b1d52a4e0758f7ca0ec234e278f
Yoga: 575c581c63e0d35c9a83f4b46d01d63abc1100ac
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

Expand Down
4 changes: 2 additions & 2 deletions Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"test": "jest"
},
"dependencies": {
"@react-native-community/art": "^1.2.0",
"react": "17.0.1",
"react-native": "0.64.2",
"react-native-progress": "*"
"react-native-progress": "*",
"react-native-svg": "^12.1.1"
},
"devDependencies": {
"@babel/core": "^7.14.6",
Expand Down
81 changes: 80 additions & 1 deletion Example/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@
"@types/yargs" "^16.0.0"
chalk "^4.0.0"

"@react-native-community/art@^1.1.2", "@react-native-community/art@^1.2.0":
"@react-native-community/art@^1.1.2":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@react-native-community/art/-/art-1.2.0.tgz#386d95393f6042d9006f9d4bc6063fb898794460"
integrity sha512-a+ZcRGl/BzLa89yi33Mbn5SHavsEXqKUMdbfLf3U8MDLElndPqUetoJyGkv63+BcPO49UMWiQRP1YUz6/zfJ+A==
Expand Down Expand Up @@ -1618,6 +1618,11 @@ big-integer@^1.6.44:
resolved "https://registry.yarnpkg.com/big-integer/-/big-integer-1.6.48.tgz#8fd88bd1632cba4a1c8c3e3d7159f08bb95b4b9e"
integrity sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w==

boolbase@^1.0.0, boolbase@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/boolbase/-/boolbase-1.0.0.tgz#68dff5fbe60c51eb37725ea9e3ed310dcc1e776e"
integrity sha1-aN/1++YMUes3cl6p4+0xDcwed24=

[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/bplist-creator/-/bplist-creator-0.0.8.tgz#56b2a6e79e9aec3fc33bf831d09347d73794e79c"
Expand Down Expand Up @@ -2038,6 +2043,29 @@ cross-spawn@^7.0.3:
shebang-command "^2.0.0"
which "^2.0.1"

css-select@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-2.1.0.tgz#6a34653356635934a81baca68d0255432105dbef"
integrity sha512-Dqk7LQKpwLoH3VovzZnkzegqNSuAziQyNZUcrdDM401iY+R5NkGBXGmtO05/yaXQziALuPogeG0b7UAgjnTJTQ==
dependencies:
boolbase "^1.0.0"
css-what "^3.2.1"
domutils "^1.7.0"
nth-check "^1.0.2"

css-tree@^1.0.0-alpha.39:
version "1.1.3"
resolved "https://registry.yarnpkg.com/css-tree/-/css-tree-1.1.3.tgz#eb4870fb6fd7707327ec95c2ff2ab09b5e8db91d"
integrity sha512-tRpdppF7TRazZrjJ6v3stzv93qxRcSsFmW6cX0Zm2NVKpxE1WV1HblnghVv9TreireHkqI/VDEsfolRF1p6y7Q==
dependencies:
mdn-data "2.0.14"
source-map "^0.6.1"

css-what@^3.2.1:
version "3.4.2"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-3.4.2.tgz#ea7026fcb01777edbde52124e21f327e7ae950e4"
integrity sha512-ACUm3L0/jiZTqfzRM3Hi9Q8eZqd6IK37mMWPLz9PJxkLWllYeRf+EHUSHYEtFop2Eqytaq1FizFVh7XfBnXCDQ==

cssom@^0.4.4:
version "0.4.4"
resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.4.4.tgz#5a66cf93d2d0b661d80bf6a44fb65f5c2e4e0a10"
Expand Down Expand Up @@ -2184,13 +2212,39 @@ diff-sequences@^27.0.6:
resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.0.6.tgz#3305cb2e55a033924054695cc66019fd7f8e5723"
integrity sha512-ag6wfpBFyNXZ0p8pcuIDS//D8H062ZQJ3fzYxjpmeKjnz8W4pekL3AI8VohmyZmsWW2PWaHgjsmqR6L13101VQ==

dom-serializer@0:
version "0.2.2"
resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-0.2.2.tgz#1afb81f533717175d478655debc5e332d9f9bb51"
integrity sha512-2/xPb3ORsQ42nHYiSunXkDjPLBaEj/xTwUO4B7XCZQTRk7EBtTOPaygh10YAAh2OI1Qrp6NWfpAhzswj0ydt9g==
dependencies:
domelementtype "^2.0.1"
entities "^2.0.0"

domelementtype@1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-1.3.1.tgz#d048c44b37b0d10a7f2a3d5fee3f4333d790481f"
integrity sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==

domelementtype@^2.0.1:
version "2.2.0"
resolved "https://registry.yarnpkg.com/domelementtype/-/domelementtype-2.2.0.tgz#9a0b6c2782ed6a1c7323d42267183df9bd8b1d57"
integrity sha512-DtBMo82pv1dFtUmHyr48beiuq792Sxohr+8Hm9zoxklYPfa6n0Z3Byjj2IV7bmr2IyqClnqEQhfgHJJ5QF0R5A==

domexception@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/domexception/-/domexception-2.0.1.tgz#fb44aefba793e1574b0af6aed2801d057529f304"
integrity sha512-yxJ2mFy/sibVQlu5qHjOkf9J3K6zgmCxgJ94u2EdvDOV09H+32LtRswEcUsmUWN72pVLOEnTSRaIVVzVQgS0dg==
dependencies:
webidl-conversions "^5.0.0"

domutils@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/domutils/-/domutils-1.7.0.tgz#56ea341e834e06e6748af7a1cb25da67ea9f8c2a"
integrity sha512-Lgd2XcJ/NjEw+7tFvfKxOzCYKZsdct5lczQ2ZaQY8Djz7pfAD3Gbp8ySJWtreII/vDlMVmxwa6pHmdxIYgttDg==
dependencies:
dom-serializer "0"
domelementtype "1"

[email protected]:
version "1.1.1"
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
Expand Down Expand Up @@ -2223,6 +2277,11 @@ end-of-stream@^1.1.0:
dependencies:
once "^1.4.0"

entities@^2.0.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/entities/-/entities-2.2.0.tgz#098dc90ebb83d8dffa089d55256b351d34c4da55"
integrity sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==

envinfo@^7.7.2:
version "7.8.1"
resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.8.1.tgz#06377e3e5f4d379fea7ac592d5ad8927e0c4d475"
Expand Down Expand Up @@ -3753,6 +3812,11 @@ map-visit@^1.0.0:
dependencies:
object-visit "^1.0.0"

[email protected]:
version "2.0.14"
resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.14.tgz#7113fc4281917d63ce29b43446f701e68c25ba50"
integrity sha512-dn6wd0uw5GsdswPFfsgMp5NSB0/aDe6fK94YJV/AJDYXL6HVLWBsxeq7js7Ad+mU2K9LAlwpk6kN2D5mwCPVow==

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
Expand Down Expand Up @@ -4267,6 +4331,13 @@ npm-run-path@^4.0.1:
dependencies:
path-key "^3.0.0"

nth-check@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/nth-check/-/nth-check-1.0.2.tgz#b2bd295c37e3dd58a3bf0700376663ba4d9cf05c"
integrity sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==
dependencies:
boolbase "~1.0.0"

nullthrows@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/nullthrows/-/nullthrows-1.1.1.tgz#7818258843856ae971eae4208ad7d7eb19a431b1"
Expand Down Expand Up @@ -4645,6 +4716,14 @@ react-native-progress@*:
"@react-native-community/art" "^1.1.2"
prop-types "^15.7.2"

react-native-svg@^12.1.1:
version "12.1.1"
resolved "https://registry.yarnpkg.com/react-native-svg/-/react-native-svg-12.1.1.tgz#5f292410b8bcc07bbc52b2da7ceb22caf5bcaaee"
integrity sha512-NIAJ8jCnXGCqGWXkkJ1GTzO4a3Md5at5sagYV8Vh4MXYnL4z5Rh428Wahjhh+LIjx40EE5xM5YtwyJBqOIba2Q==
dependencies:
css-select "^2.1.0"
css-tree "^1.0.0-alpha.39"

[email protected]:
version "0.64.2"
resolved "https://registry.yarnpkg.com/react-native/-/react-native-0.64.2.tgz#233b6ed84ac4749c8bc2a2d6cf63577a1c437d18"
Expand Down
6 changes: 3 additions & 3 deletions Pie.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Animated, StyleSheet, View } from 'react-native';
import { Surface as ARTSurface } from '@react-native-community/art';
import { Svg } from 'react-native-svg';

import Circle from './Shapes/Circle';
import Sector from './Shapes/Sector';
import withAnimation from './withAnimation';

const CIRCLE = Math.PI * 2;

const AnimatedSurface = Animated.createAnimatedComponent(ARTSurface);
const AnimatedSvg = Animated.createAnimatedComponent(Svg);
const AnimatedSector = Animated.createAnimatedComponent(Sector);

const styles = StyleSheet.create({
Expand Down Expand Up @@ -58,7 +58,7 @@ export class ProgressPie extends Component {
...restProps
} = this.props;

const Surface = rotation ? AnimatedSurface : ARTSurface;
const Surface = rotation ? AnimatedSvg : Svg;
const Shape = animated ? AnimatedSector : Sector;

const angle = animated
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# react-native-progress

Progress indicators and spinners for React Native using ReactART.
Progress indicators and spinners for React Native using React Native SVG.

![progress-demo](https://cloud.githubusercontent.com/assets/378279/11212043/64fb1420-8d01-11e5-9ec0-5e175a837c62.gif)

## Installation

`$ npm install react-native-progress --save`

### ReactART based components
### React Native SVG based components

To use the `Pie` or `Circle` components, you need to install [React Native Art](https://github.com/react-native-community/art) in your project.
To use the `Pie` or `Circle` components, you need to install [React Native SVG](https://github.com/react-native-svg/react-native-svg) in your project.

## Usage

_Note: If you don't want the ReactART based components and it's dependencies, do a deep require instead: `import ProgressBar from 'react-native-progress/Bar';`._
_Note: If you don't want the React Native SVG based components and it's dependencies, do a deep require instead: `import ProgressBar from 'react-native-progress/Bar';`._

```js
import * as Progress from 'react-native-progress';
Expand Down
14 changes: 6 additions & 8 deletions Shapes/Arc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Shape as ARTShape, Path as ARTPath } from '@react-native-community/art';
import { Path } from 'react-native-svg';

const CIRCLE = Math.PI * 2;

Expand All @@ -19,11 +19,9 @@ function makeArcPath(x, y, startAngleArg, endAngleArg, radius, direction) {
: endAngle - startAngle;

if (angle >= CIRCLE) {
return (new ARTPath())
.moveTo(x + radius, y)
.arc(0, radius * 2, radius, radius)
.arc(0, radius * -2, radius, radius)
.close();
return `M${x + radius} ${y}
a${radius} ${radius} 0 0 1 0 ${radius * 2}
a${radius} ${radius} 0 0 1 0 ${radius * -2}`;
}

const directionFactor = direction === 'counter-clockwise' ? -1 : 1;
Expand Down Expand Up @@ -86,9 +84,9 @@ export default class Arc extends Component {
);

return (
<ARTShape
<Path
d={path}
strokeCap={strokeCap}
strokeLinecap={strokeCap}
strokeWidth={strokeWidth}
{...restProps}
/>
Expand Down
Loading

0 comments on commit afd3d70

Please sign in to comment.