Files
paseo/packages/app/plugins/with-android-orientation.js
T
Mohamed Boudra 15635531c6 fix(app): keep tablet orientation policy in activity
Android resolves manifest resources without screen size qualifiers, so preserve the portrait declaration and unlock tablets when the activity starts.
2026-10-30 03:50:14 +01:00

39 lines
1.5 KiB
JavaScript

const { withMainActivity } = require("expo/config-plugins");
module.exports = function withAndroidOrientation(config) {
return withMainActivity(config, (mod) => {
const activity = mod.modResults;
if (activity.language !== "kt") throw new Error("Expected Kotlin MainActivity");
const marker = " // Paseo orientation policy";
if (!activity.contents.includes(marker)) {
const anchor = " override fun onCreate(savedInstanceState: Bundle?)";
if (!activity.contents.includes(anchor)) throw new Error("MainActivity anchor missing");
activity.contents = activity.contents.replace(
anchor,
`${marker}
private fun updateOrientation(configuration: android.content.res.Configuration) {
val orientation = if (configuration.smallestScreenWidthDp >= 600)
android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
else
android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
if (requestedOrientation != orientation) requestedOrientation = orientation
}
override fun onConfigurationChanged(newConfig: android.content.res.Configuration) {
super.onConfigurationChanged(newConfig)
updateOrientation(newConfig)
}
${anchor}`,
);
if (!activity.contents.includes(" super.onCreate(null)"))
throw new Error("MainActivity onCreate missing");
activity.contents = activity.contents.replace(
" super.onCreate(null)",
" updateOrientation(resources.configuration)\n super.onCreate(null)",
);
}
return mod;
});
};