Skip to content

Commit 5ea06b1

Browse files
committed
feat: setup react-native-svg & react-native-svg-transformer
assets 1) Add logo.svg to assets. 2) Add path alias to babel.config & tsconfig. react-native-svg 1) Install react-native-svg & run pod install. react-native-svg-transformer 1) Install react-native-svg-transformer as devDependency. 2) Add svg.d.ts file and declare module for future svg imports. 3) Update metro.config, according to installation guide. 4) Add Logo component to LogIn screen.
1 parent 515eca7 commit 5ea06b1

File tree

9 files changed

+392
-14
lines changed

9 files changed

+392
-14
lines changed

assets/images/logo.svg

Lines changed: 5 additions & 0 deletions
Loading

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
'module-resolver',
66
{
77
alias: {
8+
'@assets': './assets',
89
'@components': './src/components',
910
'@constants': './src/constants',
1011
'@screens': './src/screens',

ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ PODS:
379379
- RNScreens (3.18.2):
380380
- React-Core
381381
- React-RCTImage
382+
- RNSVG (13.6.0):
383+
- React-Core
382384
- SocketRocket (0.6.0)
383385
- Yoga (1.14.0)
384386
- YogaKit (1.18.1):
@@ -446,6 +448,7 @@ DEPENDENCIES:
446448
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
447449
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
448450
- RNScreens (from `../node_modules/react-native-screens`)
451+
- RNSVG (from `../node_modules/react-native-svg`)
449452
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
450453

451454
SPEC REPOS:
@@ -539,6 +542,8 @@ EXTERNAL SOURCES:
539542
:path: "../node_modules/react-native/ReactCommon"
540543
RNScreens:
541544
:path: "../node_modules/react-native-screens"
545+
RNSVG:
546+
:path: "../node_modules/react-native-svg"
542547
Yoga:
543548
:path: "../node_modules/react-native/ReactCommon/yoga"
544549

@@ -592,6 +597,7 @@ SPEC CHECKSUMS:
592597
React-runtimeexecutor: 15437b576139df27635400de0599d9844f1ab817
593598
ReactCommon: 349be31adeecffc7986a0de875d7fb0dcf4e251c
594599
RNScreens: 34cc502acf1b916c582c60003dc3089fa01dc66d
600+
RNSVG: 3a79c0c4992213e4f06c08e62730c5e7b9e4dc17
595601
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
596602
Yoga: 99caf8d5ab45e9d637ee6e0174ec16fbbb01bcfc
597603
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

metro.config.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@
55
* @format
66
*/
77

8-
module.exports = {
9-
transformer: {
10-
getTransformOptions: async () => ({
11-
transform: {
12-
experimentalImportSupport: false,
13-
inlineRequires: true,
14-
},
15-
}),
16-
},
17-
};
8+
const { getDefaultConfig } = require('metro-config');
9+
10+
module.exports = (async () => {
11+
const {
12+
resolver: { sourceExts, assetExts },
13+
} = await getDefaultConfig();
14+
return {
15+
transformer: {
16+
getTransformOptions: async () => ({
17+
transform: {
18+
experimentalImportSupport: false,
19+
inlineRequires: true,
20+
},
21+
}),
22+
babelTransformerPath: require.resolve('react-native-svg-transformer')
23+
},
24+
resolver: {
25+
assetExts: assetExts.filter((ext) => ext !== 'svg'),
26+
sourceExts: [...sourceExts, 'svg'],
27+
},
28+
}
29+
})

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"react-native-safe-area-context": "^4.4.1",
1818
"react-native-screens": "^3.18.2",
1919
"react-native-splash-screen": "^3.3.0",
20+
"react-native-svg": "^13.6.0",
2021
"styled-components": "^5.3.6"
2122
},
2223
"devDependencies": {
@@ -34,6 +35,7 @@
3435
"eslint": "^7.32.0",
3536
"jest": "^26.6.3",
3637
"metro-react-native-babel-preset": "0.72.3",
38+
"react-native-svg-transformer": "^1.0.0",
3739
"react-test-renderer": "18.1.0",
3840
"typescript": "^4.8.3"
3941
},

src/screens/LogIn.tsx

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
11
import React, { FC } from 'react';
2+
import { SafeAreaView, ScrollView, View, Text, StyleSheet } from 'react-native';
23

3-
export const LogIn: FC = () => <></>;
4+
import Logo from '@assets/images/logo.svg';
5+
6+
export const LogIn: FC = () => (
7+
<SafeAreaView>
8+
<ScrollView>
9+
<View style={styles.logoContainer}>
10+
<Logo width={48} height={48} />
11+
<Text style={styles.logoText}>CMK</Text>
12+
</View>
13+
</ScrollView>
14+
</SafeAreaView>
15+
);
16+
17+
const styles = StyleSheet.create({
18+
logoContainer: {
19+
alignItems: 'center',
20+
},
21+
logoText: {
22+
fontSize: 20,
23+
color: '#3F8CFF',
24+
},
25+
});

src/types/packages/svg.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// react-native-svg
2+
declare module '*.svg' {
3+
import React, { FC } from 'react';
4+
import { SvgProps } from 'react-native-svg';
5+
const content: FC<SvgProps>;
6+
export default content;
7+
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"types": ["styled-components-react-native", "node"],
1414
"baseUrl": ".",
1515
"paths": {
16+
"@assets/*": ["assets/*"],
1617
"@components/*": ["src/components/*"],
1718
"@componets": ["src/components"],
1819
"@constants/*": ["src/constants/*"],

0 commit comments

Comments
 (0)