Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mode to create react-native svg using expo #289

Merged
merged 7 commits into from Apr 10, 2019

Conversation

edpaget
Copy link
Contributor

@edpaget edpaget commented Apr 3, 2019

Summary

Using an ejected ExpoKit after version 32 prevents import Svg from 'react-native-svg'; from working, and also prevents the developer from adding
'react-native-svg' as a direct dependency since ExpoKit already provides the
library just behind the ExpoKit svg namespace. See
kristerkari/react-native-svg-transformer#13

This handles that case by allowing a expo: true flag to be passed instead of
the native option and will create the correct import statement to use Expo's
SVG library as well as prefix all non <Svg /> components with Svg..

Test plan

Added an additional test case to show the import statement and the component name prefixing.

Using an ejected ExpoKit after version 32 prevents `import Svg from
'react-native-svg';` from working, and also prevents the developer from adding
'react-native-svg' as a direct dependency since ExpoKit already provides the
library just behind the ExpoKit svg namespace. See
kristerkari/react-native-svg-transformer#13

This handles that case by allowing a `expo: true` flag to be passed instead of
the `native` option and will create the correct import statement to use Expo's
SVG library as well as prefix all non `<Svg />` components with `Svg.`.
@vercel
Copy link

vercel bot commented Apr 3, 2019

This pull request is automatically deployed with Now.
To access deployments, click Details below or on the icon next to each push.

@codecov
Copy link

codecov bot commented Apr 3, 2019

Codecov Report

Merging #289 into master will increase coverage by 0.07%.
The diff coverage is 86.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage    85.3%   85.37%   +0.07%     
==========================================
  Files          30       30              
  Lines         449      458       +9     
  Branches      125      129       +4     
==========================================
+ Hits          383      391       +8     
- Misses         55       56       +1     
  Partials       11       11
Impacted Files Coverage Δ
...s/babel-plugin-transform-svg-component/src/util.js 75% <50%> (-1.67%) ⬇️
packages/babel-preset/src/index.js 86.2% <50%> (ø) ⬆️
...bel-plugin-transform-react-native-svg/src/index.js 97.72% <94.44%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f476c8e...9ac366f. Read the comment docs.

1 similar comment
@codecov
Copy link

codecov bot commented Apr 3, 2019

Codecov Report

Merging #289 into master will increase coverage by 0.07%.
The diff coverage is 86.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage    85.3%   85.37%   +0.07%     
==========================================
  Files          30       30              
  Lines         449      458       +9     
  Branches      125      129       +4     
==========================================
+ Hits          383      391       +8     
- Misses         55       56       +1     
  Partials       11       11
Impacted Files Coverage Δ
...s/babel-plugin-transform-svg-component/src/util.js 75% <50%> (-1.67%) ⬇️
packages/babel-preset/src/index.js 86.2% <50%> (ø) ⬆️
...bel-plugin-transform-react-native-svg/src/index.js 97.72% <94.44%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f476c8e...9ac366f. Read the comment docs.

Copy link
Owner

@gregberge gregberge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @edpaget, thanks for this PR! Just a small change in the preset API. Also please check if readmes have to be updated.

if (opts.native) {
plugins.push(transformReactNativeSVG)
if (opts.native || opts.expo) {
plugins.push([transformReactNativeSVG, { expo: !!opts.expo }])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think we should use native: { expo: true } instead of a direct expo option.

@codecov-io
Copy link

Codecov Report

Merging #289 into master will increase coverage by 0.07%.
The diff coverage is 86.36%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage    85.3%   85.37%   +0.07%     
==========================================
  Files          30       30              
  Lines         449      458       +9     
  Branches      125      129       +4     
==========================================
+ Hits          383      391       +8     
- Misses         55       56       +1     
  Partials       11       11
Impacted Files Coverage Δ
...s/babel-plugin-transform-svg-component/src/util.js 75% <50%> (-1.67%) ⬇️
packages/babel-preset/src/index.js 86.2% <50%> (ø) ⬆️
...bel-plugin-transform-react-native-svg/src/index.js 97.72% <94.44%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f476c8e...e86ae78. Read the comment docs.

@codecov-io
Copy link

codecov-io commented Apr 6, 2019

Codecov Report

Merging #289 into master will increase coverage by 0.56%.
The diff coverage is 91.3%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #289      +/-   ##
==========================================
+ Coverage    85.3%   85.86%   +0.56%     
==========================================
  Files          30       30              
  Lines         449      460      +11     
  Branches      125      130       +5     
==========================================
+ Hits          383      395      +12     
+ Misses         55       54       -1     
  Partials       11       11
Impacted Files Coverage Δ
...s/babel-plugin-transform-svg-component/src/util.js 81.25% <100%> (+4.58%) ⬆️
packages/babel-preset/src/index.js 87.09% <66.66%> (+0.88%) ⬆️
...bel-plugin-transform-react-native-svg/src/index.js 97.72% <94.11%> (+0.42%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f476c8e...c5c7523. Read the comment docs.

@vercel vercel bot temporarily deployed to staging April 6, 2019 17:14 Inactive
@edpaget edpaget force-pushed the ep-add-support-for-expokit-svg branch from e86ae78 to 31849a6 Compare April 6, 2019 17:15
@edpaget
Copy link
Contributor Author

edpaget commented Apr 6, 2019

Thanks for the review @neoziro (and for the library!). I've change the option to expect the native: { expo: true } argument and updated the options documentation. I'm not sure if there's another place that should be added in the documentation.

@vercel vercel bot temporarily deployed to staging April 6, 2019 17:15 Inactive
@gregberge
Copy link
Owner

Thanks @edpaget, could you fix tests please? Also please run yarn format, thanks!

@gregberge
Copy link
Owner

Thanks!

@edpaget edpaget deleted the ep-add-support-for-expokit-svg branch April 10, 2019 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants