Skip to content

Commit

Permalink
feat(android): add onConfigurationChanged() activity lifecycle hook (#…
Browse files Browse the repository at this point in the history
…3936)

Co-authored-by: Carl Poole <carl@ionic.io>
  • Loading branch information
imhoffd and carlpoole committed Dec 11, 2020
1 parent 54f9d49 commit 29e9e2c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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

0 comments on commit 29e9e2c

Please sign in to comment.