Skip to content
New issue

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

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

Already on GitHub? # to your account

Update ShadowListener.java for newArch #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TajSinghESGI
Copy link

Support newArch.

  • UIManagerModule is deprecated in favor of UIManager in the New Architecture.

Support newArch.
- UIManagerModule is deprecated in favor of UIManager in the New Architecture.
@rushant11
Copy link

@TajSinghESGI @aliyanlatif have you found out any solution of this crashing issue on android?

@aliyanlatif
Copy link

@TajSinghESGI @aliyanlatif have you found out any solution of this crashing issue on android?

yes i followed all the changes mentioned in this PR and it did the job for me and then i created patch package for it

@rushant11
Copy link

@TajSinghESGI @aliyanlatif have you found out any solution of this crashing issue on android?

yes i followed all the changes mentioned in this PR and it did the job for me and then i created patch package for it

Can you give me that updated file now?

@rushant11
Copy link

@TajSinghESGI @aliyanlatif have you found out any solution of this crashing issue on android?

yes i followed all the changes mentioned in this PR and it did the job for me and then i created patch package for it

I copy paste the code of this shadowlistener file and after that applied patch-package, but still error is getting in android.

@aliyanlatif
Copy link

@rushant11 copy this code and replace it with the shadowListener.java file code, then create a patch package

package com.curvedbottombar;

import android.os.CountDownTimer;
import android.view.View;
import android.view.ViewGroup;

import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.common.UIManagerType;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.uimanager.events.EventDispatcherListener;
import com.facebook.react.views.image.ReactImageView;
import com.facebook.react.views.view.ReactViewGroup;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ShadowListener implements EventDispatcherListener {

private Map<Integer, ShadowLayout> imageIds = new HashMap<>();
private List viewsToFadeIn = new ArrayList<>();
private ReactContext reactContext;
private EventDispatcher eventDispatcher;

private CountDownTimer fadeTimer;

public ShadowListener(ReactContext reactContext) {
this.reactContext = reactContext;

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
  // Utiliser le nouvel UIManager pour Fabric
  eventDispatcher =
    UIManagerHelper
      .getUIManager(reactContext, UIManagerType.FABRIC)
      .getEventDispatcher();
} else {
  // Architecture ancienne
  eventDispatcher =
    reactContext
      .getNativeModule(com.facebook.react.uimanager.UIManagerModule.class)
      .getEventDispatcher();
}

if (eventDispatcher != null) {
  eventDispatcher.addListener(this);
}

}

public void onAddView(ShadowLayout parent, View child) {
if (child instanceof ReactImageView) {
((ReactImageView) child).setShouldNotifyLoadEvents(true);
this.imageIds.put(child.getId(), parent);
} else if (child instanceof ReactViewGroup) {
for (int index = 0; index < ((ViewGroup) child).getChildCount(); ++index) {
View nextChild = ((ViewGroup) child).getChildAt(index);
this.onAddView(parent, nextChild);
}
}
}

@OverRide
public void onEventDispatch(final Event event) {
if (UiThreadUtil.isOnUiThread()) {
handleEvent(event);
} else {
UiThreadUtil.runOnUiThread(() -> handleEvent(event));
}
}

private void handleEvent(Event event) {
if ("topLoadEnd".equals(event.getEventName()) && this.imageIds.containsKey(event.getViewTag())) {
ShadowLayout layout = this.imageIds.get(event.getViewTag());
this.viewsToFadeIn.add(layout);
if (this.fadeTimer != null) this.fadeTimer.cancel();
this.fadeTimer = new CountDownTimer(500, 33) {
@OverRide
public void onTick(long millisUntilFinished) {
for (ShadowLayout view : viewsToFadeIn) view.invalidate();
}

    @Override
    public void onFinish() {
      for (ShadowLayout view : viewsToFadeIn) view.invalidate();
      viewsToFadeIn.clear();
    }
  }.start();
}

}

public void tearDown() {
if (eventDispatcher != null) {
eventDispatcher.removeListener(this);
}
}
}

@rushant11
Copy link

@rushant11 copy this code and replace it with the shadowListener.java file code, then create a patch package

package com.curvedbottombar;

import android.os.CountDownTimer; import android.view.View; import android.view.ViewGroup;

import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.uimanager.UIManagerHelper; import com.facebook.react.uimanager.common.UIManagerType; import com.facebook.react.uimanager.events.Event; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.EventDispatcherListener; import com.facebook.react.views.image.ReactImageView; import com.facebook.react.views.view.ReactViewGroup;

import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;

public class ShadowListener implements EventDispatcherListener {

private Map<Integer, ShadowLayout> imageIds = new HashMap<>(); private List viewsToFadeIn = new ArrayList<>(); private ReactContext reactContext; private EventDispatcher eventDispatcher;

private CountDownTimer fadeTimer;

public ShadowListener(ReactContext reactContext) { this.reactContext = reactContext;

if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
  // Utiliser le nouvel UIManager pour Fabric
  eventDispatcher =
    UIManagerHelper
      .getUIManager(reactContext, UIManagerType.FABRIC)
      .getEventDispatcher();
} else {
  // Architecture ancienne
  eventDispatcher =
    reactContext
      .getNativeModule(com.facebook.react.uimanager.UIManagerModule.class)
      .getEventDispatcher();
}

if (eventDispatcher != null) {
  eventDispatcher.addListener(this);
}

}

public void onAddView(ShadowLayout parent, View child) { if (child instanceof ReactImageView) { ((ReactImageView) child).setShouldNotifyLoadEvents(true); this.imageIds.put(child.getId(), parent); } else if (child instanceof ReactViewGroup) { for (int index = 0; index < ((ViewGroup) child).getChildCount(); ++index) { View nextChild = ((ViewGroup) child).getChildAt(index); this.onAddView(parent, nextChild); } } }

@OverRide public void onEventDispatch(final Event event) { if (UiThreadUtil.isOnUiThread()) { handleEvent(event); } else { UiThreadUtil.runOnUiThread(() -> handleEvent(event)); } }

private void handleEvent(Event event) { if ("topLoadEnd".equals(event.getEventName()) && this.imageIds.containsKey(event.getViewTag())) { ShadowLayout layout = this.imageIds.get(event.getViewTag()); this.viewsToFadeIn.add(layout); if (this.fadeTimer != null) this.fadeTimer.cancel(); this.fadeTimer = new CountDownTimer(500, 33) { @OverRide public void onTick(long millisUntilFinished) { for (ShadowLayout view : viewsToFadeIn) view.invalidate(); }

    @Override
    public void onFinish() {
      for (ShadowLayout view : viewsToFadeIn) view.invalidate();
      viewsToFadeIn.clear();
    }
  }.start();
}

}

public void tearDown() { if (eventDispatcher != null) { eventDispatcher.removeListener(this); } } }

Okay, It worked thank you.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants