forked from StasDoskalenko/react-native-google-fit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.plugin.js
More file actions
54 lines (43 loc) · 1.36 KB
/
app.plugin.js
File metadata and controls
54 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const {
AndroidConfig,
withAndroidManifest,
createRunOncePlugin,
} = require('expo/config-plugins')
let pkg = { name: 'react-native-google-fit' }
try {
pkg = require('./package.json')
} catch {
// empty catch block
}
/**
* Expo config plugin for react-native-google-fit
* Adds necessary Android configurations for Google Fit API
*/
const withGoogleFit = (config) => {
return withAndroidManifest(config, (config) => {
const androidManifest = config.modResults
// Ensure queries element exists
if (!androidManifest.manifest.queries) {
androidManifest.manifest.queries = []
}
// Add Google Fit package query for Android 11+
const queries = androidManifest.manifest.queries[0]
if (!queries) {
androidManifest.manifest.queries[0] = { package: [] }
}
const packages = androidManifest.manifest.queries[0].package || []
// Check if Google Fit query already exists
const googleFitQuery = {
$: { 'android:name': 'com.google.android.apps.fitness' },
}
const hasGoogleFitQuery = packages.some(
(pkg) => pkg.$?.['android:name'] === 'com.google.android.apps.fitness'
)
if (!hasGoogleFitQuery) {
packages.push(googleFitQuery)
}
androidManifest.manifest.queries[0].package = packages
return config
})
}
module.exports = createRunOncePlugin(withGoogleFit, pkg.name, pkg.version)