Skip to content

Commit 088866a

Browse files
satchljclaude
andcommitted
fix(mobile): anchor the display-metrics bind on the onConfigurationChanged override
Look for the full override signature before inserting after its super call, so a matching string elsewhere in MainActivity can't receive the bind call. The generated MainActivity is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3b69498 commit 088866a

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

‎apps/mobile/plugins/withAndroidWindowDisplayMetrics.cjs‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ const SET_CONTENT_VIEW_METHOD = `
4747
}
4848
`;
4949

50+
const CONFIGURATION_CHANGED_SIGNATURE =
51+
"override fun onConfigurationChanged(newConfig: Configuration) {";
52+
5053
const BIND_CALL = `
5154
bindWindowDisplayMetrics()`;
5255

@@ -94,13 +97,16 @@ module.exports = function withAndroidWindowDisplayMetrics(config) {
9497
);
9598
// Another plugin (withAndroidTabletOrientation) may already override
9699
// onConfigurationChanged; extend it rather than declaring a second override.
97-
if (contents.includes("super.onConfigurationChanged(newConfig)")) {
98-
contents = insertAfter(
99-
contents,
100-
"super.onConfigurationChanged(newConfig)",
101-
BIND_CALL,
102-
"the super.onConfigurationChanged call",
103-
);
100+
const overrideStart = contents.indexOf(CONFIGURATION_CHANGED_SIGNATURE);
101+
if (overrideStart !== -1) {
102+
contents =
103+
contents.slice(0, overrideStart) +
104+
insertAfter(
105+
contents.slice(overrideStart),
106+
"super.onConfigurationChanged(newConfig)",
107+
BIND_CALL,
108+
"the super call in the onConfigurationChanged override",
109+
);
104110
} else {
105111
contents = addImport(contents, "import android.content.res.Configuration");
106112
contents = insertAfter(

0 commit comments

Comments
 (0)