diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 84665dd338..f562168420 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -180,6 +180,8 @@ android { dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) + implementation project(':rctmgl') + implementation "com.facebook.react:react-native:+" // From node_modules if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 7c996a3a87..ff72434dab 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,3 +1,7 @@ rootProject.name = 'RNMapboxGLExample' + +include ':rctmgl' +project(':rctmgl').projectDir = new File(rootProject.projectDir, '../../android/rctmgl') + apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' diff --git a/example/babel.config.js b/example/babel.config.js index f842b77fcf..0887f3527a 100644 --- a/example/babel.config.js +++ b/example/babel.config.js @@ -1,3 +1,30 @@ module.exports = { presets: ['module:metro-react-native-babel-preset'], + plugins: [ + '@babel/plugin-transform-modules-commonjs', + [ + 'module-resolver', + { + alias: { + '@react-native-mapbox-gl/maps': '../javascript/index', + // from maps/package.json + react: './node_modules/react', + 'react-native': './node_modules/react-native', + '@turf/helpers': './node_modules/@turf/helpers', + '@turf/distance': './node_modules/@turf/distance', + '@turf/nearest-point-on-line': './node_modules/@turf/nearest-point-on-line', + '@turf/length': './node_modules/@turf/length', + '@turf/along': './node_modules/@turf/along', + '@mapbox/geo-viewport': './node_modules/@mapbox/geo-viewport', + 'underscore': './node_modules/underscore', + + '@babel': './node_modules/@babel', + fbjs: './node_modules/fbjs', + 'hoist-non-react-statics': './node_modules/hoist-non-react-statics', + invariant: './node_modules/invariant', + 'prop-types': './node_modules/prop-types', + }, + } + ] + ].filter(Boolean), }; diff --git a/example/ios/Podfile b/example/ios/Podfile index efa5d1676f..54fad66a9c 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -32,14 +32,14 @@ target 'RNMapboxGLExample' do pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec' pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec' pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec' - pod 'react-native-mapbox-gl', :path => '../node_modules/@react-native-mapbox-gl/maps' + pod 'react-native-mapbox-gl', :path => '../../' target 'RNMapboxGLExampleTests' do inherit! :search_paths # Pods for testing end - pod 'NoUseFrameworks-MapboxMobileEvents', :podspec => '../node_modules/@react-native-mapbox-gl/maps/ios/NoUseFrameworks-MapboxMobileEvents/NoUseFrameworks-MapboxMobileEvents.podspec.json' + pod 'NoUseFrameworks-MapboxMobileEvents', :podspec => '../../ios/NoUseFrameworks-MapboxMobileEvents/NoUseFrameworks-MapboxMobileEvents.podspec.json' # use_frameworks! use_native_modules! diff --git a/example/metro.config.js b/example/metro.config.js index 13a964217f..042f9840f0 100644 --- a/example/metro.config.js +++ b/example/metro.config.js @@ -4,8 +4,36 @@ * * @format */ +const blacklist = require('metro-config/src/defaults/blacklist'); +const path = require('path'); + +const glob = require('glob-to-regexp'); + +function getBlacklist() { + const nodeModuleDirs = [ + glob(`${path.resolve(__dirname, '..')}/node_modules/*`), + glob(`${path.resolve(__dirname, '..')}/docs/*`), + glob(`${path.resolve(__dirname, '..')}/e2e/*`), + glob(`${path.resolve(__dirname)}/node_modules/*/node_modules/fbjs/*`), + glob( + `${path.resolve( + __dirname + )}/node_modules/*/node_modules/hoist-non-react-statics/*` + ), + glob( + `${path.resolve( + __dirname + )}/node_modules/react-native/node_modules/@babel/*` + ), + ]; + return blacklist(nodeModuleDirs); +} module.exports = { + resolver: { + blacklistRE: getBlacklist(), + }, + watchFolders: [path.resolve(__dirname, '..')], transformer: { getTransformOptions: async () => ({ transform: { diff --git a/example/package.json b/example/package.json index 82a8687421..16aa5f6e50 100644 --- a/example/package.json +++ b/example/package.json @@ -8,22 +8,16 @@ "start": "react-native start", "test": "jest", "lint": "eslint .", - "copy:changes": "node ./scripts/watch_rngl.js", - "pack:gl": "./scripts/npm_pack_rngl.sh", - "clean:node:modules": "./scripts/clean_node_modules.sh", - "preinstall": "npm run pack:gl", - "postinstall": "node ./scripts/set_access_token.js && jetifier", - "reset:from:gl": "npm run clean:node:modules && npm install" + "postinstall": "node ./scripts/set_access_token.js && jetifier" }, "dependencies": { "@mapbox/geo-viewport": "^0.4.0", "@mapbox/mapbox-sdk": "^0.6.0", - "@react-native-mapbox-gl/maps": "file:../react-native-mapbox-gl-maps.tgz", "@turf/along": "^5.1.5", "@turf/bbox-polygon": "^6.0.1", "@turf/bearing": "^5.1.5", "@turf/distance": "^5.1.5", - "@turf/helpers": "^4.7.3", + "@turf/helpers": "^6.1.4", "@turf/length": "^6.0.2", "@turf/line-distance": "^4.7.3", "@turf/nearest": "^4.7.3", @@ -38,7 +32,10 @@ "react-native-safe-area-view": "^0.13.1", "react-native-vector-icons": "^6.6.0", "react-navigation": "^2.18.3", - "url": "^0.11.0" + "url": "^0.11.0", + + "underscore": "^1.8.3", + "@turf/nearest-point-on-line": ">= 4.0.0 <7.0.0" }, "devDependencies": { "@babel/core": "^7.6.2", @@ -46,6 +43,8 @@ "@react-native-community/eslint-config": "^0.0.5", "babel-jest": "^24.9.0", "eslint": "^6.8.0", + "glob-to-regexp": "^0.4.0", + "babel-plugin-module-resolver": "^3.2.0", "jest": "^24.9.0", "jetifier": "^1.6.4", "metro-react-native-babel-preset": "^0.56.0", diff --git a/example/scripts/clean_node_modules.sh b/example/scripts/clean_node_modules.sh deleted file mode 100755 index 4881d5b7ab..0000000000 --- a/example/scripts/clean_node_modules.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -echo "Removing package-lock and removing node modules" -rm package-lock.json -rm -rf node_modules diff --git a/example/scripts/npm_pack_rngl.sh b/example/scripts/npm_pack_rngl.sh deleted file mode 100755 index ad20fbf8f9..0000000000 --- a/example/scripts/npm_pack_rngl.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -echo "Moving into ${RNGL}" -cd ../ - -echo "Attempting to pack react-native-mapbox-gl" - -name=$(npm pack) - -echo "Renaming $name" - -mv "$name" "react-native-mapbox-gl-maps.tgz" \ No newline at end of file diff --git a/example/scripts/watch_rngl.js b/example/scripts/watch_rngl.js deleted file mode 100755 index c400b91343..0000000000 --- a/example/scripts/watch_rngl.js +++ /dev/null @@ -1,66 +0,0 @@ -const path = require('path'); - -// eslint-disable-next-line import/no-extraneous-dependencies -const fs = require('fs-extra'); - -const RNGL_DIR = path.join('..'); -const RNGL_EXAMPLE_DIR = path.join( - 'node_modules', - '@react-native-mapbox-gl', - 'maps', -); - -function copyFile(source, dest) { - return new Promise((resolve, reject) => { - fs.copy(source, dest, err => { - if (err) { - return reject(err); - } - return resolve(); - }); - }); -} - -async function main() { - try { - console.log('Copying javascript'); - await copyFile( - path.join(RNGL_EXAMPLE_DIR, 'javascript'), - path.join(RNGL_DIR, 'javascript'), - ); - - console.log('Copying typescript'); - await copyFile( - path.join(RNGL_EXAMPLE_DIR, 'index.d.ts'), - path.join(RNGL_DIR, 'index.d.ts'), - ); - - console.log('Copying java'); - await copyFile( - path.join(RNGL_EXAMPLE_DIR, 'android', 'rctmgl', 'src'), - path.join(RNGL_DIR, 'android', 'rctmgl', 'src'), - ); - - console.log('Copying gradle file'); - await copyFile( - path.join(RNGL_EXAMPLE_DIR, 'android', 'rctmgl', 'build.gradle'), - path.join(RNGL_DIR, 'android', 'rctmgl', 'build.gradle'), - ); - - console.log('Copying objc'); - await copyFile( - path.join(RNGL_EXAMPLE_DIR, 'ios', 'RCTMGL'), - path.join(RNGL_DIR, 'ios', 'RCTMGL'), - ); - - console.log('Copying xcode project'); - await copyFile( - path.join(RNGL_EXAMPLE_DIR, 'ios', 'RCTMGL.xcodeproj'), - path.join(RNGL_DIR, 'ios', 'RCTMGL.xcodeproj'), - ); - } catch (e) { - console.log(e); - } -} - -main();