Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 01ebe09

Browse files
kakulguptargabs
authored andcommitted
Proofing chapter svg icons (#30)
* Proofing chapter svg icons * Proofing internationalization * Proofing custom native modules
1 parent 61b874f commit 01ebe09

File tree

8 files changed

+120
-121
lines changed

8 files changed

+120
-121
lines changed
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# Icons in react-native
22

3-
Those who come from web development background knows the power of svg icons. We always prefer svg\(for icons, images\) and what not. Benefits of SVGs are:
3+
Those who come from a web development background know the power of SVG icons. We prefer using SVGs \(for icons, images\) because of the following reasons:
44

5-
* They are resolution independent\(scalable\)
6-
* They provide you more flexibility in changing color etc.
7-
* They are lesser in size as compared to an image.
8-
* They are written in XML syntax so you can put directly inside your html without worrying about bundling your assets.
5+
* They are resolution independent\(scalable\).
6+
* They provide us more flexibility in changing color.
7+
* They are smaller in size as compared to images.
8+
* They are written in XML syntax so they can be inserted directly into HTML without worrying about bundling assets.
99

10-
### That was about web, does react-native support SVGs?
10+
### That was on the web. Does react-native support SVGs?
1111

12-
Unfortunately, rendering SVGs in native is not as simple as it is in HTML/WEB, where you can just use SVG as image IMG or copy paste svg content inside your HTML. Unlike web, react-native doesn't support SVGs out of the box. Though there are some plugins which lets you render SVGs, but they do not support all SVG elements and it is not very easy to use.
12+
Unfortunately, rendering SVGs in native is not as simple as it is in HTML/Web, where you can use SVG as an image or copy paste SVG content inside your HTML. Unlike the web, react-native doesn't support SVG out of the box. Though there are some plugins which let you render SVG, they do not support all SVG elements and are not very easy to use.
1313

14-
### How do you get the power of SVG in native environment?
14+
### How do you get the power of SVG in a native environment?
1515

16-
Let me introduce you to this amazing library called [`react-native-vector-icons`](https://github.com/oblador/react-native-vector-icons). It comes bundled with a bunch of icon sets\(default is [`FontAwesome`](https://fontawesome.com/icons)\).
16+
Let me introduce you to this amazing library called [`react-native-vector-icons`](https://github.com/oblador/react-native-vector-icons). It comes bundled with a bunch of icon sets\(default is [`FontAwesome`](https://fontawesome.com/icons)\).
1717

18-
* All the fonts are scalable and you can style them just like SVGs.
19-
* It returns a react component which accepts name, etc. as prop. After integration, the usage will be as simple as `<Icon name="rocket" size={30} color="#900" />`
18+
* All the fonts are scalable and you can style them just like SVG.
19+
* It returns a React component which accepts name, etc. as prop. After integration, the usage will be as simple as `<Icon name="rocket" size={30} color="#900" />`
2020
* You can pass custom style.
21-
* It also supports a couple of other components which might be useful. Ex, Button with an icon \(`<Icon.Button />`\)
22-
* You can also create your own iconset if you want to use custom icons.
23-
* Installation is a 2 step process if you wish to use the icons provided by FontAwesome or other similar font libraries. (yarn add and react-native link)
24-
* If you wish to use custom fonts(made in svg), please read the next chapter.
21+
* It also supports a couple of other components which might be useful. Example: button with an icon \(`<Icon.Button />`\)
22+
* You can also create your own icon set if you want to use custom icons.
23+
* Installation is a 2 step process if you wish to use the icons provided by FontAwesome or other similar font libraries. (`yarn add` and `react-native link`)
24+
* If you wish to use custom fonts(made in SVG), please read the next chapter.
Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1-
# Creating custom iconset
1+
# Creating custom icon set
22

3-
`react-native-vector-icons` support using custom icon sets if you do not want to use the icons which come bundled or if you want to add your own icons. It supports Fontello and IcoMoon to create custom fonts. We used icomoon to convert our svgs to a config which is readable by the library.
3+
`react-native-vector-icons` supports using custom icon sets if you do not want to use the icons which come bundled with it or if you want to add your own icons. It supports Fontello and IcoMoon to create custom fonts. We used IcoMoon to convert our SVGs to a config which is readable by the library.
44

55

66
### Setting up the framework
7-
Install the NPM module using NPM or Yarn.
7+
Install the npm module using npm or Yarn.
88
```js
99
npm install --save react-native-vector-icons
1010
```
11-
OR
11+
or
1212
```js
1313
yarn add react-native-vector-icons
1414
```
1515

1616

17-
### Configuring your project to support custom iconsets.
17+
### Configuring your project to support custom icon sets.
1818

19-
We will use IcoMoon to support custom icons/fonts. Icomoon is free and open source application which lets you convert a set of svg icons to fonts. It is a front end only app and does not upload your icons anywhere, so no privacy concerns!
19+
We will use IcoMoon to support custom icons/fonts. Icomoon is a free and open source application which lets you convert a set of SVG icons to fonts. It is a front end only app and does not upload your icons anywhere, so there will be no privacy concerns!
2020

2121
The steps for the configuration are as follows:
2222

23-
* Create a resources folder where we will keep our custom fontfile(.ttf).
23+
* Create a resources folder where we will keep our custom font file (.ttf).
2424

25-
* Do `react-native link react-native-vector-icons`. This will setup the vector icons framework for you.
25+
* Do `react-native link react-native-vector-icons`. This will set up the vector icons framework for you.
2626

27-
That's it, you are done with the setup. Now we need to get the ttf file and place it inside the `resources/fonts` that we just created.
27+
That's it, you are done with the setup. Now we need to get the TTF file and place it in the `resources/fonts` folder that we just created.
2828

29-
### How to generate .ttf fonts using icomoon:
29+
### How to generate .ttf fonts using IcoMoon:
3030

31-
1. Open the [iconmoon application.](https://icomoon.io/app)
31+
1. Open the [IcoMoon application.](https://icomoon.io/app)
3232

33-
2. Remove the current set(if there is one) and create a new empty set and give your preferred name(Remember to give same name everywhere).
33+
2. Remove the current set(if there is one) and create a new empty set and give your preferred name (remember to give the same name everywhere).
3434
<br>
3535
<div style="text-align:center">
3636
<img src="/assets/images/12/1.png" style="width: 80%;display:inline-block;" hspace="20">
3737
</div>
3838
<br>
3939

40-
3. Drag and drop your SVG files on the tool.
40+
3. Drag and drop your SVG files onto the tool.
4141
<br>
4242
<div style="text-align:center">
4343
<img src="/assets/images/12/2.png" style="width: 80%;display:inline-block;" hspace="20">
@@ -57,22 +57,22 @@ That's it, you are done with the setup. Now we need to get the ttf file and plac
5757
</div>
5858
<br>
5959

60-
5. After the selection, click generate font. This will download a zip file on your system.
60+
5. After the selection, click Generate Font. This will download a zip file to your system.
6161
<br>
6262
<div style="text-align:center">
6363
<img src="/assets/images/12/5.png" style="width: 80%;display:inline-block;" hspace="20">
6464
</div>
6565
<br>
6666

67-
6. The zip file will contain a selection.json file fonts folder containing a .ttf file. We only need these two files to use fonts in react-native.
67+
6. The zip file will contain a selection.json file and a fonts folder containing a .ttf file. We only need these two files to use fonts in react-native.
6868
<br>
6969
<div style="text-align:center">
7070
<img src="/assets/images/12/6.png" style="width: 40%;display:inline-block;vertical-align: middle;margin:0" hspace="40">
7171
<img src="/assets/images/12/7.png" style="width: 40%;display:inline-block;vertical-align: middle;margin:0" hspace="40">
7272
</div>
7373
<br>
7474

75-
7. Put the fontfile(.ttf) in `resources/fonts` folder and add the following script to the package.json:
75+
7. Put the font file (.ttf) in the `resources/fonts` folder and add the following script to the package.json:
7676

7777
```
7878
"rnpm": {
@@ -82,17 +82,17 @@ That's it, you are done with the setup. Now we need to get the ttf file and plac
8282
]
8383
}
8484
```
85-
This script will copy the font files to both android and iOS folders. After this, whenever we want to update the fonts, we will do `react-native link react-native-vector-icons` and the fonts will be copied/updated automatically to both android and iOS projects.
85+
This script will copy the font files to both Android and iOS folders. After this, whenever we want to update the fonts, we will do `react-native link react-native-vector-icons` and the fonts will be copied/updated automatically to both Android and iOS projects.
8686

87-
8. Put the JSON file (selection.json) in your app and create a file called CustomIcon.js and import the selection.json which you exported in the previous step.
87+
8. Put the JSON file (selection.json) in your app and create a file called CustomIcon.js. Import the selection.json in CustomIcon.js.
8888

8989
```js
9090
import {createIconSetFromIcoMoon} from 'react-native-vector-icons';
9191
import icoMoonConfig from './selection.json';
9292
export default createIconSetFromIcoMoon(icoMoonConfig);
9393
```
9494

95-
9. That's it, to use a font simply import the file as a react component and pass the icon name and size(optional) or even style.
95+
9. That's it! To use a font simply import the file as a React component and pass the icon name and size(optional) or even style.
9696

9797
```js
9898
import CustomIcon from './components/CustomIcon.js'
@@ -102,14 +102,14 @@ That's it, you are done with the setup. Now we need to get the ttf file and plac
102102
<CustomIcon name='android' style={styles.androidIcon} /> // To pass custom tyle
103103
```
104104

105-
### Changing file names of the fontfile
106-
The default name of the fontfile is `icomoon.ttf`. If you want to give a different name, go to Preferences after step 5 and change the name there before downloading. Also, make sure that if you change the fontfile name, give the same name to the set as well(by default its "Untitled Set")
105+
### Changing file names of the font file
106+
The default name of the font file is `icomoon.ttf`. If you want to give it a different name, go to Preferences after step 5 and change the name there before downloading. Also, make sure that if you change the font file name, give the same name to the set as well(by default it is "Untitled Set").
107107

108-
It is not recommended to change the filename of `.ttf` fontfile after the setup/native linking. The filename gets written in `project.pbxproj` and `Info.plist` and the file gets copied to ` android/app/src/main/assets/fonts/` once you run the link command. If you wish to change the filename, you would need to take care of changing the above 2 files as well, and removing the unused icon from android folder which might cause problems if not done properly._
108+
It is not recommended to change the filename of `.ttf` font file after the setup/native linking. The filename gets written in `project.pbxproj` and `Info.plist` and the file gets copied to ` android/app/src/main/assets/fonts/` once you run the link command. If you wish to change the filename, you would need to take care of changing the above 2 files as well, and removing the unused icon from the android folder which might cause problems if not done properly.
109109

110-
### How do I add/delete icons from the fontfile(.ttf)
110+
### How do I add/delete icons from the font file (.ttf)
111111

112-
You can easily change/delete the contents of fontfile. The tool just needs `selection.json` file, which defines the font configuration. The steps for the same are as follows:
112+
You can easily change/delete the contents of the font file. The tool only needs the `selection.json` file, which defines the font configuration. The steps for the same are as follows:
113113

114114
1. Open [IcoMoon App](https://icomoon.io/app/#/select)
115115

@@ -120,22 +120,22 @@ You can easily change/delete the contents of fontfile. The tool just needs `sele
120120
</div>
121121
<br>
122122

123-
* Edit/Delete the icon using the tools on top. (Adding the Icon is same as step 3 mentioned above)
123+
* Edit/delete the icon using the tools on top. (Adding an icon is the same as step 3 mentioned above)
124124
<br>
125125
<div style="text-align:center">
126126
<img src="/assets/images/12/9.png" style="width: 80%;display:inline-block;" hspace="20">
127127
</div>
128128
<br>
129129

130-
* After the editing is complete, generate a new fontfile by following the steps 5 and 6 mentioned above. Once you have the new fontfile and the new selection.json file, place them in their locations and do `react-native link react-native-vector-icons`.
130+
* After the editing is complete, generate a new font file by following the steps 5 and 6 mentioned above. Once you have the new font file and the new selection.json file, place them in their appropriate locations in the app and do `react-native link react-native-vector-icons`.
131131

132-
That's how you you change the icons. Pretty neat huh?
132+
That's how you change the icons. Pretty neat huh?
133133

134134

135-
###### This will let us convert any svg image to font which is scalable, platform independent and easy to style. What else can you ask for, right?
135+
###### This will let us convert any SVG image to a font which is scalable, platform independent and easy to style. What else can you ask for, right?
136136
<div style="text-align:center">
137137
<img src="/assets/images/12/giphy.gif" style="width: 80%;display:inline-block;" hspace="20">
138138
</div>
139139
<br>
140140

141-
The code till here can be found on the **branch** [chapter/11](https://github.com/react-made-native-easy/note-taker/tree/chapter/11)
141+
The code till here can be found on the **branch** [chapter/12](https://github.com/react-made-native-easy/note-taker/tree/chapter/12)

‎13-internationalization/13.1-framework-intro.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# Internationalization
22

3-
For application developers, internationalizing an application means abstracting all of the strings and other localespecific things like date, currency etc.
3+
For application developers, internationalizing an application means abstracting all of the strings and other locale-specific things like date, currency etc.
44

5-
We will create a file called `en.js` and `hi.js` containing all the strings in a flat JSON format. Our Presentational components will import the string from one of these files depending on the current language. Both the language files will contain same keys at any point of time.
5+
We will create a file called `en.js` and `hi.js` containing all the strings in a flat JSON format. Our presentational components will import the strings from one of these files depending on the current language. Both the language files will contain the same keys at any point in time.
66

77

88
### Framework for Internationalization
99

10-
We will be using [react-native-i18n](https://www.npmjs.com/package/react-native-i18n). It integrates [I18n.js](https://github.com/fnando/i18n-js) with React Native and uses the user preferred locale as default. `I18n.js` is a very famous vanilla JS library which supports features like Date/Time localization, Number localization, Locale fallback, etc. You can find more info about i18n.js [here](https://github.com/fnando/i18n-js);
10+
We will be using [react-native-i18n](https://www.npmjs.com/package/react-native-i18n). It integrates [i18n.js](https://github.com/fnando/i18n-js) with React Native and uses the user preferred locale as default. `I18n.js` is a very famous vanilla JS library which supports features like date/time localization, number localization, locale fallback, etc. You can find more info about i18n.js [here](https://github.com/fnando/i18n-js).
1111

12-
Note that the only feature this module gives us is getting the device locale as default app locale. If you do not need this feature, you may skip installing the native module and use [i18n-js](https://www.npmjs.com/package/i18n-js) module instead.
12+
Note that the only feature this module gives us is setting the device locale as default app locale. If you do not need this feature, you may skip installing the native module and use the [i18n-js](https://www.npmjs.com/package/i18n-js) module instead.
1313

1414
### Setting up the framework
1515

16-
1. Lets start by installing the NPM module.
16+
1. Let's start by installing the npm module.
1717

1818
`yarn add react-native-i18n`
1919

2020
2. After this is done, we would need to link it to our app using
2121

2222
`react-native link react-native-i18n`
2323

24-
3. Create language js files containing language strings in flat JSON format. We will follow the convention of `<PAGENAME>_contentTypeInCameCase`. Reason for this convention is it will be easier of the testers/devs to know if a translation is missing, considering, we will be having `guess` mode ON(explained later).
24+
3. Create language js files containing language strings in flat JSON format. We will follow the convention of `<PAGENAME>_contentTypeInCameCase`. The reason for this convention is that it will be easier for the testers/devs to know if a translation is missing considering we will be having `guess` mode enabled (explained later).
2525

2626
>Example: config/language/en.js
2727
@@ -39,7 +39,7 @@ Note that the only feature this module gives us is getting the device locale as
3939
ABOUT_theCreatorsDesc: 'About the Creators',
4040
};
4141
```
42-
4. Create a utility file which will export a translate function and a some other utility functions.
42+
4. Create a utility file which will export a translate function and some other utility functions.
4343

4444
*Refer to the comments to know what each line/function does*
4545
>utils/language.utils.js
@@ -49,7 +49,7 @@ Note that the only feature this module gives us is getting the device locale as
4949
import en from '../config/language/en';
5050
import hi from '../config/language/hi';
5151

52-
I18n.fallbacks = true; // If an english translation is not available in en.js, it will look inside hi.js
52+
I18n.fallbacks = true; // If an English translation is not available in en.js, it will look inside hi.js
5353
I18n.missingBehaviour = 'guess'; // It will convert HOME_noteTitle to "HOME note title" if the value of HOME_noteTitle doesn't exist in any of the translation files.
5454
I18n.defaultLocale = 'en'; // If the current locale in device is not en or hi
5555
I18n.locale = 'en'; // If we do not want the framework to use the phone's locale by default
@@ -66,7 +66,7 @@ Note that the only feature this module gives us is getting the device locale as
6666
export const getCurrentLocale = () => I18n.locale; // It will be used to define intial language state in reducer.
6767

6868
/* translateHeaderText:
69-
screenProps => coming from react-navigation(defined in app.container.js)
69+
screenProps => coming from react-navigation(defined in app.container.js)
7070
langKey => will be passed from the routes file depending on the screen.(We will explain the usage later int the coming topics)
7171
*/
7272
export const translateHeaderText = (langKey) => ({screenProps}) => {
@@ -78,29 +78,29 @@ Note that the only feature this module gives us is getting the device locale as
7878

7979
```
8080

81-
5. Setup is done, now lets import the translations from the utility file instead of hardcoding it the components.
81+
5. Setup is done. Nowlet's import the translations from the utility file instead of hardcoding it in the components.
8282
8383
Instead of
8484
```js
8585
<Text style={styles.characterCount}>{text.length} characters</Text>
8686
```
8787
88-
We will do
88+
we will write
8989
```js
9090
<Text style={styles.characterCount}>{text.length} {translate('HOME_characters')}</Text>
9191
```
9292
93-
After following the above 5 steps, we will have Internationalization framework setup and all our strings coming from a single language config file.
93+
After following the above 5 steps, we will have an internationalization framework setup and all our strings coming from a single language config file.
9494
95-
Lets change the defaultLocale of the app from `en` to `hi` in `language.utils.js` and see if our framework setup works.
95+
Let's change the defaultLocale of the app from `en` to `hi` in `language.utils.js` and see if our framework setup works.
9696

9797
<br>
9898
<div style="text-align:center">
9999
<img src="/assets/images/13/13.1.png" style="width: 40%;display:inline-block;" hspace="20">
100100
</div>
101101
<br>
102102

103-
TADA! Our setup works like a charm and we can see everything in `hindi`
103+
TADA! Our setup works like a charm and we can see everything in `Hindi`
104104

105105

106106
{% exposnack %}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /