Skip to content

Commit

Permalink
Fix more warnings on bridge invalidation
Browse files Browse the repository at this point in the history
Summary:
Looked at the top soft exceptions firing from this codepath. Most of these should use `getReactApplicationContext` instead of `getReactApplicationContextIfActiveOrWarn` to do their cleanup on invalidation.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D43661307

fbshipit-source-id: 27094a6e8dfcf4748eb916531c4998f1c9ee8713
  • Loading branch information
javache authored and pull[bot] committed Mar 28, 2023
1 parent f713bdb commit 4a2d125
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,8 @@ public void initialize() {

@Override
public void invalidate() {
getReactApplicationContext().removeLifecycleEventListener(this);
super.invalidate();

ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
applicationContext.removeLifecycleEventListener(this);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ public void run() {

@Override
public void invalidate() {
getReactApplicationContext().removeLifecycleEventListener(this);
super.invalidate();

ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
applicationContext.removeLifecycleEventListener(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package com.facebook.react.modules.fresco;

import android.content.Context;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.drawee.backends.pipeline.Fresco;
Expand Down Expand Up @@ -127,13 +126,14 @@ public FrescoModule(
@Override
public void initialize() {
super.initialize();
getReactApplicationContext().addLifecycleEventListener(this);

ReactApplicationContext reactContext = getReactApplicationContext();
reactContext.addLifecycleEventListener(this);
if (!hasBeenInitialized()) {
if (mConfig == null) {
mConfig = getDefaultConfig(getReactApplicationContext());
mConfig = getDefaultConfig(reactContext);
}
Context context = getReactApplicationContext().getApplicationContext();
Fresco.initialize(context, mConfig);
Fresco.initialize(reactContext.getApplicationContext(), mConfig);
sHasBeenInitialized = true;
} else if (mConfig != null) {
FLog.w(
Expand Down Expand Up @@ -219,11 +219,7 @@ private ImagePipeline getImagePipeline() {

@Override
public void invalidate() {
getReactApplicationContext().removeLifecycleEventListener(this);
super.invalidate();

ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
applicationContext.removeLifecycleEventListener(this);
}
}
}

0 comments on commit 4a2d125

Please sign in to comment.