Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): add onConfigurationChanged() activity lifecycle hook #3936

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
Expand Down Expand Up @@ -962,6 +963,16 @@ public void onNewIntent(Intent intent) {
}
}

/**
* Handle an onConfigurationChanged event and notify the plugins
* @param newConfig
*/
public void onConfigurationChanged(Configuration newConfig) {
for (PluginHandle plugin : plugins.values()) {
plugin.getInstance().handleOnConfigurationChanged(newConfig);
}
}

/**
* Handle onRestart lifecycle event and notify the plugins
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.getcapacitor;

import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import com.getcapacitor.android.R;
Expand Down Expand Up @@ -195,4 +196,15 @@ public void onBackPressed() {

this.bridge.onBackPressed();
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

if (this.bridge == null) {
return;
}

this.bridge.onConfigurationChanged(newConfig);
}
}
7 changes: 7 additions & 0 deletions android/capacitor/src/main/java/com/getcapacitor/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
Expand Down Expand Up @@ -690,6 +691,12 @@ protected void handleOnActivityResult(int requestCode, int resultCode, Intent da
*/
protected void handleOnNewIntent(Intent intent) {}

/**
* Handle onConfigurationChanged
* @param newConfig
*/
protected void handleOnConfigurationChanged(Configuration newConfig) {}

/**
* Handle onStart
*/
Expand Down