@fortawesome/react-native-fontawesome 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,451 +10,24 @@
10
10
 
11
11
  <!-- toc -->
12
12
 
13
- - [Introduction](#introduction)
14
- + [Upgrading Font Awesome?](#upgrading-font-awesome)
15
- + [Get started](#get-started)
16
- + [Learn about our new SVG implementation](#learn-about-our-new-svg-implementation)
17
- - [Installation](#installation)
18
- - [Add more styles or Pro icons](#add-more-styles-or-pro-icons)
19
- - [or with Yarn](#or-with-yarn)
20
- - [Usage](#usage)
21
- * [Explicit Import](#explicit-import)
22
- * [Build a Library to Reference Icons Throughout Your App More Conveniently](#build-a-library-to-reference-icons-throughout-your-app-more-conveniently)
23
- * [Color](#color)
24
- + [Color Prop](#color-prop)
25
- + [Change Color with a StyleSheet](#color-stylesheet-property)
26
- * [Size](#size)
27
- - [Features](#features)
28
- * [Duotone](#duotone)
29
- * [Masking](#masking)
30
- * [Power Transforms](#power-transforms)
31
- - [Frequent questions](#frequent-questions)
32
- * [How do I import the same icon from two different styles?](#how-do-i-import-the-same-icon-from-two-different-styles)
33
- * [I don't think tree-shaking is working; got any advice?](#i-dont-think-tree-shaking-is-working-got-any-advice)
13
+ - [Documentation](#documentation)
34
14
  - [How to Help](#how-to-help)
35
15
  - [Contributors](#contributors)
36
16
 
37
17
  <!-- tocstop -->
38
18
 
39
- ## Introduction
19
+ ## Documentation
40
20
 
41
- Hey there! We're glad you're here...
42
-
43
- #### Upgrading Font Awesome?
44
-
45
- If you've used Font Awesome in the past (version 5 or older) there are some
46
- things that you should learn before you dive in.
47
-
48
- > https://fontawesome.com/v6/docs/web/setup/upgrade/
49
-
50
- #### Get started
51
-
52
- This package is for integrating with React Native. If you aren't using React Native then it's
53
- not going to help you. Head over to our "Get Started" page for some guidance.
54
-
55
- > https://fontawesome.com/v6/docs/web/setup/quick-start
56
-
57
- #### Learn about our new SVG implementation
58
-
59
- This package, under the hood, uses SVG with JS and the `@fortawesome/fontawesome-svg-core` library. This implementation differs drastically from
60
- the web fonts implementation that was used in version 4 and older of Font Awesome. You might head over there to learn about how it works.
61
-
62
- > https://fontawesome.com/v6/docs/web/dig-deeper/svg-core
63
-
64
- ## Installation
65
-
66
- ```
67
- $ npm i --save react-native-svg # **
68
- $ npm i --save @fortawesome/fontawesome-svg-core
69
- $ npm i --save @fortawesome/free-solid-svg-icons
70
- $ npm i --save @fortawesome/react-native-fontawesome
71
- ```
72
-
73
- ** `create-react-native-app` uses Expo, which bundles `react-native-svg`. So if you're using `create-react-native-app`
74
- you shouldn't try to add `react-native-svg`. At the time of writing, `create-react-native-app` bundles
75
- `react-native-svg` version 6, which does not include support for SVG features such as `Mask`. In order to make use of `Mask`, make sure your dependencies have `react-native-svg` 7. The example app in this repo demonstrates.
76
-
77
- If you are using a bare react-native-cli project, run the following command to complete the setup on iOS.
78
-
79
- ```
80
- $ cd ios && pod install
81
- ```
82
-
83
- ## Add more styles or Pro icons
84
-
85
- Brands are separated into their own style and for customers upgrading from
86
- version 4 to 5 we have a limited number of Regular icons available.
87
-
88
- **Visit [fontawesome.com/icons](https://fontawesome.com/icons) to search for free and Pro icons**
89
-
90
- ```
91
- $ npm i --save @fortawesome/free-brands-svg-icons
92
- $ npm i --save @fortawesome/free-regular-svg-icons
93
- ```
94
-
95
- If you are a [Font Awesome Pro](https://fontawesome.com/pro) subscriber you can install Pro packages; this requires [additional configuration](https://fontawesome.com/v6/docs/web/setup/packages).
96
-
97
- ```
98
- $ npm i --save @fortawesome/pro-solid-svg-icons
99
- $ npm i --save @fortawesome/pro-regular-svg-icons
100
- $ npm i --save @fortawesome/pro-light-svg-icons
101
- ```
102
-
103
- If you'd like to use Duotone icons, you'll need to add Duotone package:
104
-
105
- ```
106
- $ npm i --save @fortawesome/pro-duotone-svg-icons
107
- ```
108
-
109
-
110
- ## or with Yarn
111
-
112
- ```
113
- $ yarn add @fortawesome/fontawesome-svg-core
114
- $ yarn add @fortawesome/free-solid-svg-icons
115
- $ yarn add @fortawesome/react-native-fontawesome
116
- ```
117
-
118
- ## Usage
119
-
120
- You can use Font Awesome icons in your React Native components as simply as this:
121
-
122
- ```javascript
123
- <FontAwesomeIcon icon="mug-saucer" />
124
- ```
125
-
126
- That simple usage is made possible when you add the `"mug-saucer"` icon, to the
127
- _library_.
128
-
129
- This is one of the two ways you can use Font Awesome with React Native. We'll
130
- summarize both ways briefly and then get into the details of each below.
131
-
132
- 1. **Explicit Import**
133
-
134
- Allows icons to be subsetted, optimizing your final bundle. Only the icons
135
- you import are included in the bundle. However, explicitly importing icons
136
- into each of many components in your app might become tedious, so you may
137
- want to build a library.
138
-
139
- 2. **Build a Library**
140
-
141
- Explicitly import icons just once in some init module. Then add them to the
142
- library. Then reference any of them by icon name as a string from any
143
- component. No need to import the icons into each component once they're in
144
- the library.
145
-
146
- ### Explicit Import
147
-
148
- For this example, we'll also reference the `@fortawesome/free-solid-svg-icons`
149
- module, so make sure you've added it to the project as well:
150
-
151
- ```
152
- $ npm i --save @fortawesome/free-solid-svg-icons
153
- ```
154
-
155
- or
156
-
157
- ```
158
- $ yarn add @fortawesome/free-solid-svg-icons
159
- ```
160
-
161
- Now, a simple React Native component might look like this:
162
-
163
- ```javascript
164
- import React, { Component } from 'react'
165
- import { View } from 'react-native'
166
- import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
167
- import { faMugSaucer } from '@fortawesome/free-solid-svg-icons/faMugSaucer'
168
-
169
- type Props = {}
170
- export default class App extends Component<Props> {
171
- render() {
172
- return (
173
- <View>
174
- <FontAwesomeIcon icon={ faMugSaucer } />
175
- </View>
176
- )
177
- }
178
- }
179
- ```
180
-
181
- Notice that the `faMugSaucer` icon is imported from
182
- `@fortawesome/free-solid-svg-icons/faMugSaucer` as an object and then provided to the
183
- `icon` prop as an object.
184
-
185
- Explicitly importing icons like this allows us to subset Font Awesome's
186
- thousands of icons to include only those you use in your final bundled file.
187
-
188
- ### Build a Library to Reference Icons Throughout Your App More Conveniently
189
-
190
- You probably want to use our icons in more than one component in your app,
191
- right?
192
-
193
- But with explicit importing, it could become tedious to import into each of
194
- your app's components every icon you want to reference in that component.
195
-
196
- So, add them to the _library_. Do this setup once in some initializing module
197
- of your app, adding all of the icons you'll use in your app's React components.
198
-
199
- Suppose `App.js` initializes my app, including the library. For this example,
200
- we'll add two individual icons, `faSquareCheck` and `faMugSaucer`. We also add all
201
- of the brands in `@fortawesome/free-brands-svg-icons`. This example would
202
- illustrate the benefits of building a library even more clearly if it involved
203
- fifty or a hundred icons, but we'll keep the example brief and leave it to your
204
- imagination as to how this might scale up with lots of icons.
205
-
206
- Don't forget to add `@fortawesome/free-brands-svg-icons`:
207
-
208
- ```
209
- $ npm i --save @fortawesome/free-brands-svg-icons
210
- ```
211
-
212
- or
213
-
214
- ```
215
- $ yarn add @fortawesome/free-brands-svg-icons
216
- ```
217
-
218
- In `App.js`, where our app is initialized:
219
-
220
- ```javascript
221
- // ...
222
- import { library } from '@fortawesome/fontawesome-svg-core'
223
- import { fab } from '@fortawesome/free-brands-svg-icons'
224
- import { faSquareCheck } from '@fortawesome/free-solid-svg-icons/faSquareCheck'
225
- import { faMugEmpty } from '@fortawesome/free-solid-svg-icons/faMugEmpty'
226
-
227
- library.add(fab, faSquareCheck, faMugSaucer)
228
- ```
229
-
230
- OK, so what's happening here?
231
-
232
- In our call to <span style="white-space:nowrap;">`library.add()`</span> we're passing
233
-
234
- - `fab`: which represents _all_ of the brand icons in
235
- <span style="white-space:nowrap;">`@fortawesome/free-brands-svg-icons`</span>.
236
- So any of the brand icons in that package may be referenced by icon name
237
- as a string anywhere else in our app.
238
- For example: `"apple"`, `"microsoft"`, or `"google"`.
239
- - `faSquareCheck` and `faMugSaucer`: Adding each of these icons individually
240
- allows us to refer to them throughout our app by their icon string names,
241
- `"square-check"` and `"mug-saucer"`, respectively.
242
-
243
- Now, suppose you also have React Native components `Beverage` and `Gadget` in your app.
244
- You don't have to re-import your icons into them. Just import the `FontAwesomeIcon`
245
- component, and when you use it, supply the icon prop an icon name as a string.
246
-
247
- We'll make `Beverage.js` a functional component:
248
-
249
- ```javascript
250
- import React from 'react'
251
- import { View, Text } from 'react-native'
252
- import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
253
-
254
- export const Beverage = () => (
255
- <View>
256
- <FontAwesomeIcon icon="square-check" />
257
- <Text>Favorite beverage: </Text><FontAwesomeIcon icon="mug-saucer" />
258
- </View>
259
- )
260
- ```
261
-
262
- There's one another piece of magic that's happening in the background when
263
- providing icon names as strings like this: the `fas` prefix (for Font Awesome
264
- Solid) is being inferred as the default. Later, we'll look at what that means
265
- and how we can do something different than the default.
266
-
267
- Now suppose `Gadget.js` looks like this:
268
-
269
- ```javascript
270
- import React from 'react'
271
- import { View, Text } from 'react-native'
272
- import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
273
-
274
- export const Gadget = () => (
275
- <View>
276
- <FontAwesomeIcon icon="square-check" />
277
- <Text>Popular gadgets come from vendors like:</Text>
278
- <FontAwesomeIcon icon={['fab', 'apple']} />
279
- <FontAwesomeIcon icon={['fab', 'microsoft']} />
280
- <FontAwesomeIcon icon={['fab', 'google']} />
281
- </View>
282
- )
283
- ```
284
-
285
- Notice:
286
-
287
- - We used the `"square-check"` icon name again in this component, though we
288
- didn't have to explicitly import it into this component. With one explicit import of
289
- that icon in `App.js`, and adding it to the library, we've managed to use
290
- it by name in multiple components.
291
- - We used the `"apple"`, `"microsoft"`, and `"google"` brand icons, which were
292
- never explicitly _individually_ imported, but they're available to us by
293
- name as strings because `fab` was added to our library in `App.js`, and
294
- `fab` includes all of those icons.
295
- - We added the `fab` prefix to reference those brand icons.
296
-
297
- Adding a prefix—and the syntax we used to do it—are new. So what's
298
- going on here?
299
-
300
- First, recall when we introduced `<FontAwesomeIcon icon="mug-saucer"/>` and learned
301
- that a prefix of `fas` was being added to `"mug-saucer"` by default.
302
-
303
- The `"square-check"` icon is getting a default prefix of `fas` here too, which
304
- is what we want, because that icon also lives in the
305
- `@fortawesome/free-solid-svg-icons` package.
306
-
307
- However, the `"apple"`, `"microsoft"`, and `"google"` brand icons live in the
308
- package `@fortawesome/free-brands-svg-icons`. So we need to specify a
309
- different prefix for them—not the default `fas`, but `fab`, for Font Awesome
310
- _Brand_.
311
-
312
- When specifying a prefix with an icon name, both are given as strings.
313
-
314
- Now, what about that syntax?
315
-
316
- The `icon` prop expects a single object:
317
-
318
- - It could be an icon object, like `{faMugSaucer}`.
319
- - It could a string object, like `"mug-saucer"`.
320
- (The curly braces around a string object supplied to a prop are optional,
321
- so we've omitted them.)
322
- - Or it could be an `Array` of strings, where the first element is a prefix,
323
- and the second element is the icon name: `{["fab", "apple"]}`
324
-
325
- ### Color
326
-
327
- Priority: The color prop takes priority over setting color via StyleSheet. So if you end up with both set,
328
- the prop wins.
329
-
330
- In fact, when provided a style object (suppose you've declared other style properties other
331
- than `color`), if the color prop has been specified, then any color property on the style object is removed
332
- before the style object is passed through to the underlying SVG rendering library. This is to avoid ambiguity.
333
-
334
- Using the color prop should be preferred over using the StyleSheet.
335
-
336
- #### Color Prop
337
-
338
- ```javascript
339
- <FontAwesomeIcon icon={ faMugSaucer } color={ 'red' } />
340
- ```
341
-
342
- #### Color StyleSheet property
343
-
344
- To set the color of an icon, provide a `StyleSheet` like this:
345
-
346
- ```javascript
347
- import React, { Component } from 'react'
348
- import { View, StyleSheet } from 'react-native'
349
- import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
350
- import { faMugSaucer } from '@fortawesome/free-solid-svg-icons/faMugSaucer'
351
-
352
- type Props = {}
353
-
354
- const style = StyleSheet.create({
355
- icon: {
356
- color: 'blue'
357
- }
358
- })
359
-
360
- export default class App extends Component<Props> {
361
- render() {
362
- return (
363
- <View>
364
- <FontAwesomeIcon icon={ faMugSaucer } style={ style.icon } />
365
- </View>
366
- )
367
- }
368
- }
369
- ```
370
-
371
- ### Size
372
-
373
- Default: 16
374
-
375
- To adjust the size, use the `size` prop:
376
-
377
- ```javascript
378
- <FontAwesomeIcon icon={ faMugSaucer } size={ 32 } />
379
- ```
380
-
381
- Note: the `height` and `width` props have been deprecated.
382
-
383
- ## Features
384
-
385
- ### Duotone
386
-
387
- ```javascript
388
- <FontAwesomeIcon icon="mug-saucer" color="blue" secondaryColor="red" secondaryOpacity={ 0.4 } />
389
- ```
390
-
391
- You can specify the color and opacity for Duotone's secondary layer using the `secondaryColor` and `secondaryOpacity` props. Note that these are optional, and will simply default to using your primary color at 40% opacity.
392
-
393
- ### Masking
394
-
395
- ```javascript
396
- <FontAwesomeIcon icon="mug-saucer" mask={['far', 'circle']} />
397
- ```
398
-
399
- [More on masking...](https://fontawesome.com/v6/docs/web/style/mask#contentHeader)
400
-
401
- ### Power Transforms
402
-
403
- ```javascript
404
- <FontAwesomeIcon icon="arrows-up-down-left-right" transform="shrink-6 left-4" />
405
- <FontAwesomeIcon icon="arrow-right" transform={{ rotate: 42 }} />
406
- ```
407
-
408
- [More on power transforms...](https://fontawesome.com/v6/docs/web/style/power-transform#contentHeader)
409
-
410
- ## Frequent questions
411
-
412
- ### How do I import the same icon from two different styles?
413
-
414
- With ES modules and `import` statements we can rename:
415
-
416
- ```javascript
417
- import { library } from '@fortawesome/fontawesome-svg-core'
418
- import { faStroopwafel as fasFaStroopwafel } from '@fortawesome/pro-solid-svg-icons/faStroopwafel'
419
- import { faStroopwafel as farFaStroopwafel } from '@fortawesome/pro-regular-svg-icons/faStroopwafel'
420
-
421
- library.add(fasFaStroopwafel, farFaStroopwafel)
422
- ```
423
-
424
- ### I don't think tree-shaking is working; got any advice?
425
-
426
- Check out our [docs here](https://fontawesome.com/v6/docs/apis/javascript/tree-shaking).
427
-
428
- If you find that your build times are taking forever, check the way that you are importing icons.
429
-
430
- In past versions of `react-native-fontawesome` we've documented importing icons like this:
431
-
432
- ```javascript
433
- import { faStroopwafel } from '@fortawesome/pro-solid-svg-icons'
434
- ```
435
-
436
- This can cause build times for your project to skyrocket because React Native is trying to tree shake. The Font Awesome
437
- packages are so large that we _highly_ recommend that you avoid this.
438
-
439
- Instead, use "deep imports" by default.
440
-
441
- ```javascript
442
- import { faStroopwafel } from '@fortawesome/pro-solid-svg-icons/faStroopwafel' // <- notice the additional module here?
443
- ```
444
-
445
- By directly importing from the `faStroopwafel.js` module there is no additional work that tree shaking needs to do in order to
446
- reduce your bundle size.
21
+ Official documentation is hosted at fontawesome.com: [Check it out here](https://fontawesome.com/docs/web/use-with/react-native/)
447
22
 
448
23
  ## How to Help
449
24
 
450
- Review the following docs before diving in:
25
+ 1. Review the following docs before diving in:
451
26
 
452
27
  - [CONTRIBUTING.md](CONTRIBUTING.md)
453
28
  - [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)
454
29
 
455
- And then:
456
-
457
- 1. Check the existing issues and see if you can help!
30
+ 2. Check the existing issues and see if you can help!
458
31
 
459
32
  ## Contributors
460
33
 
@@ -467,4 +40,5 @@ Community:
467
40
  | Jeremey | [@puremana](https://github.com/puremana) |
468
41
  | Michael Schonfeld | [@schonfeld](https://github.com/schonfeld) |
469
42
  | Ádám Gólya | [@golya](https://github.com/golya) |
43
+ | Greg Marut | [@gregmarut](https://github.com/gregmarut) |
470
44
  | Font Awesome Team | [@FortAwesome](https://github.com/orgs/FortAwesome/people)|
@@ -74,17 +74,29 @@ function normalizeIconArgs(icon) {
74
74
  }
75
75
 
76
76
  function FontAwesomeIcon(props) {
77
- var iconArgs = props.icon,
78
- maskArgs = props.mask,
79
- maskId = props.maskId,
80
- height = props.height,
81
- width = props.width,
82
- size = props.size;
83
-
84
- var style = _reactNative.StyleSheet.flatten(props.style);
77
+ var _props = _objectSpread({
78
+ icon: null,
79
+ mask: null,
80
+ maskId: null,
81
+ transform: null,
82
+ style: {},
83
+ color: null,
84
+ secondaryColor: null,
85
+ secondaryOpacity: null,
86
+ size: DEFAULT_SIZE
87
+ }, props);
88
+
89
+ var iconArgs = _props.icon,
90
+ maskArgs = _props.mask,
91
+ maskId = _props.maskId,
92
+ height = _props.height,
93
+ width = _props.width,
94
+ size = _props.size;
95
+
96
+ var style = _reactNative.StyleSheet.flatten(_props.style);
85
97
 
86
98
  var iconLookup = normalizeIconArgs(iconArgs);
87
- var transform = objectWithKey('transform', typeof props.transform === 'string' ? _fontawesomeSvgCore.parse.transform(props.transform) : props.transform);
99
+ var transform = objectWithKey('transform', typeof _props.transform === 'string' ? _fontawesomeSvgCore.parse.transform(_props.transform) : _props.transform);
88
100
  var mask = objectWithKey('mask', normalizeIconArgs(maskArgs));
89
101
  var renderedIcon = (0, _fontawesomeSvgCore.icon)(iconLookup, _objectSpread(_objectSpread(_objectSpread({}, transform), mask), {}, {
90
102
  maskId: maskId
@@ -97,12 +109,12 @@ function FontAwesomeIcon(props) {
97
109
 
98
110
  var _abstract = renderedIcon["abstract"]; // This is the color that will be passed to the "fill" prop of the Svg element
99
111
 
100
- var color = props.color || style.color || DEFAULT_COLOR; // This is the color that will be passed to the "fill" prop of the secondary Path element child (in Duotone Icons)
112
+ var color = _props.color || style.color || DEFAULT_COLOR; // This is the color that will be passed to the "fill" prop of the secondary Path element child (in Duotone Icons)
101
113
  // `null` value will result in using the primary color, at 40% opacity
102
114
 
103
- var secondaryColor = props.secondaryColor || color; // Secondary layer opacity should default to 0.4, unless a specific opacity value or a specific secondary color was given
115
+ var secondaryColor = _props.secondaryColor || color; // Secondary layer opacity should default to 0.4, unless a specific opacity value or a specific secondary color was given
104
116
 
105
- var secondaryOpacity = props.secondaryOpacity || DEFAULT_SECONDARY_OPACITY; // To avoid confusion down the line, we'll remove properties from the StyleSheet, like color, that are being overridden
117
+ var secondaryOpacity = _props.secondaryOpacity || DEFAULT_SECONDARY_OPACITY; // To avoid confusion down the line, we'll remove properties from the StyleSheet, like color, that are being overridden
106
118
  // or resolved in other ways, to avoid ambiguity as to which inputs cause which outputs in the underlying rendering process.
107
119
  // In other words, we don't want color (for example) to be specified via two different inputs.
108
120
 
@@ -141,17 +153,6 @@ FontAwesomeIcon.propTypes = {
141
153
  maskId: _propTypes["default"].string,
142
154
  transform: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].object])
143
155
  };
144
- FontAwesomeIcon.defaultProps = {
145
- icon: null,
146
- mask: null,
147
- maskId: null,
148
- transform: null,
149
- style: {},
150
- color: null,
151
- secondaryColor: null,
152
- secondaryOpacity: null,
153
- size: DEFAULT_SIZE
154
- };
155
156
 
156
157
  var convertCurry = _converter["default"].bind(null, _react["default"].createElement);
157
158
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fortawesome/react-native-fontawesome",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Official React Native component for Font Awesome",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -26,7 +26,8 @@
26
26
  "Michael Schonfeld <github.com/schonfeld>",
27
27
  "Ádám Gólya <github.com/golya>",
28
28
  "Edward Emanuel <github.com/ej2>",
29
- "Jason Lundien <github.com/jasonlundien>"
29
+ "Jason Lundien <github.com/jasonlundien>",
30
+ "Greg Marut <github.com/gregmarut>"
30
31
  ],
31
32
  "license": "MIT",
32
33
  "peerDependencies": {