-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.plugin.js
More file actions
57 lines (51 loc) · 2.02 KB
/
app.plugin.js
File metadata and controls
57 lines (51 loc) · 2.02 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
55
56
57
const { withAndroidManifest } = require('@expo/config-plugins');
/**
* Ensure MainActivity has android:windowSoftInputMode set.
* Default mode: 'adjustResize'.
*/
function setWindowSoftInputMode(manifest, mode = 'adjustResize') {
try {
const app = manifest?.manifest?.application?.[0];
if (!app) return manifest;
const activities = app['activity'] ?? [];
// Heuristic: main activity is the one with LAUNCHER category
// or name ending with 'MainActivity'.
const mainActivity = activities.find((activity) => {
const attrs = activity?.['$'] ?? {};
const name = attrs['android:name'] ?? '';
const intentFilters = activity['intent-filter'] ?? [];
const hasLauncher = intentFilters.some((filter) => {
const categories = filter['category'] ?? [];
return categories.some((c) => c?.['$']?.['android:name'] === 'android.intent.category.LAUNCHER');
});
return hasLauncher || name.endsWith('MainActivity') || name === '.MainActivity';
});
if (mainActivity) {
mainActivity['$'] = mainActivity['$'] || {};
mainActivity['$']['android:windowSoftInputMode'] = mode;
}
} catch (e) {
// Silently ignore to avoid breaking prebuild; user can inspect logs if needed
}
return manifest;
}
module.exports = function withWindowSoftInputMode(config, props = { mode: 'adjustResize' }) {
return withAndroidManifest(config, (cfg) => {
const manifest = cfg.modResults;
cfg.modResults = setWindowSoftInputMode(manifest, props?.mode);
try {
const appManifest = cfg.modResults?.manifest || {};
const usesPermissions = appManifest['uses-permission'] || [];
const hasBilling = usesPermissions.some((p) => p?.['$']?.['android:name'] === 'com.android.vending.BILLING');
if (!hasBilling) {
usesPermissions.push({
$: { 'android:name': 'com.android.vending.BILLING' },
});
appManifest['uses-permission'] = usesPermissions;
}
} catch (e) {
// silent: avoid breaking prebuild
}
return cfg;
});
};