Skip to content

Commit

Permalink
Added web support using react-native-web, using expo for web only
Browse files Browse the repository at this point in the history
Signed-off-by: sarthakpranesh <[email protected]>
  • Loading branch information
sarthakpranesh committed Feb 15, 2021
1 parent 5e438a3 commit 2ae1dc6
Show file tree
Hide file tree
Showing 7 changed files with 2,578 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,7 @@ buck-out/
/ios/Pods/

.env

# Expo used for web and web builds
/.expo
/web-build
5 changes: 5 additions & 0 deletions App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ const MainApp = () => {
useEffect(() => {
// some bug in react native
setTimeout(() => {
if (Platform.OS === 'web') {
getLocation({ lat: '28.644800', long: '77.216721' })
return
}

if (Platform.OS === 'ios') {
Geolocation.requestAuthorization('whenInUse')
.then((result) => {
Expand Down
5 changes: 4 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"name": "Covid19",
"displayName": "Covid19"
"displayName": "Covid19",
"expo": {
"platform": ["web"]
}
}
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
['module-resolver', {
alias: {
'react-native-linear-gradient': 'react-native-web-linear-gradient'
}
}]
],
env: {
production: {
}
Expand Down
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
* @format
*/
import React from 'react'
import { AppRegistry, StatusBar } from 'react-native'
import {
AppRegistry,
StatusBar,
Platform
} from 'react-native'
import App from './App'
import { name as appName } from './app.json'

Expand All @@ -22,3 +26,9 @@ export default function Main () {
}

AppRegistry.registerComponent(appName, () => Main)

if (Platform.OS === 'web') {
AppRegistry.runApplication(appName, {
rootTag: document.getElementById('root')
})
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"@react-navigation/drawer": "^5.8.0",
"@react-navigation/native": "^5.4.3",
"@react-navigation/stack": "^5.4.0",
"expo": "^40.0.1",
"node-fetch": "^2.6.1",
"react": "16.11.0",
"react-dom": "16.11.0",
"react-native": "0.62.2",
"react-native-geolocation-service": "^5.0.0",
"react-native-gesture-handler": "^1.6.1",
Expand All @@ -31,6 +33,8 @@
"react-native-svg": "^12.1.0",
"react-native-unimodules": "^0.9.1",
"react-native-vector-icons": "^6.6.0",
"react-native-web": "~0.11",
"react-native-web-linear-gradient": "^1.1.1",
"react-navigation": "^4.4.0"
},
"devDependencies": {
Expand All @@ -45,6 +49,8 @@
"@typescript-eslint/eslint-plugin": "^3.9.0",
"@typescript-eslint/parser": "^3.9.0",
"babel-jest": "^26.0.1",
"babel-plugin-module-resolver": "^4.1.0",
"babel-plugin-react-native-web": "^0.15.0",
"eslint": "^7.7.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.22.0",
Expand Down
Loading

0 comments on commit 2ae1dc6

Please sign in to comment.