diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java index 1e4918bb1d67f6..1d0d41d82c8379 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/util/ReactFindViewUtil.java @@ -2,16 +2,16 @@ package com.facebook.react.uimanager.util; -import javax.annotation.Nullable; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import android.view.View; import android.view.ViewGroup; - import com.facebook.react.R; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; /** * Finds views in React Native view hierarchies @@ -19,6 +19,8 @@ public class ReactFindViewUtil { private static final List mOnViewFoundListeners = new ArrayList<>(); + private static final Map> + mOnMultipleViewsFoundListener = new HashMap<>(); /** * Callback to be invoked when a react native view has been found @@ -37,6 +39,18 @@ public interface OnViewFoundListener { void onViewFound(View view); } + /** + * Callback to be invoked when all react native views with geiven NativeIds have been found + */ + public interface OnMultipleViewsFoundListener{ + + void onViewFound(View view, String nativeId); + /** + * Called when all teh views have been found + * @param map + */ + } + /** * Finds a view that is tagged with {@param nativeId} as its nativeID prop * under the {@param root} view hierarchy. Returns the view if found, null otherwise. @@ -90,6 +104,14 @@ public static void removeViewListener(OnViewFoundListener onViewFoundListener) { mOnViewFoundListeners.remove(onViewFoundListener); } + public static void addViewsListener(OnMultipleViewsFoundListener listener, Set ids) { + mOnMultipleViewsFoundListener.put(listener, ids); + } + + public static void removeViewsListener(OnMultipleViewsFoundListener listener) { + mOnMultipleViewsFoundListener.remove(listener); + } + /** * Invokes any listeners that are listening on this {@param view}'s native id */ @@ -106,6 +128,21 @@ public static void notifyViewRendered(View view) { iterator.remove(); } } + + Iterator>> + viewIterator = mOnMultipleViewsFoundListener.entrySet().iterator(); + while (viewIterator.hasNext()) { + Map.Entry> entry = + viewIterator.next(); + Set nativeIds = entry.getValue(); + if (nativeIds.contains(nativeId)) { + entry.getKey().onViewFound(view, nativeId); + nativeIds.remove(nativeId); // remove it from list of NativeIds to search for. + } + if (nativeIds.isEmpty()) { + viewIterator.remove(); + } + } } private static @Nullable String getNativeId(View view) {