mirror of
https://github.com/Tencent/Hippy.git
synced 2026-10-28 21:48:13 +08:00
fix(android): sendComponentEvent with view==null crash
This commit is contained in:
+10
-5
@@ -57,12 +57,17 @@ public class ViewPagerPageChangeListener implements ViewPager.OnPageChangeListen
|
||||
params.put(PAGE_ITEM_POSITION, position);
|
||||
EventUtils.sendComponentEvent(mPager, EventUtils.EVENT_PAGE_SELECTED, params);
|
||||
View currView = mPager.getViewFromAdapter(mCurrPageIndex);
|
||||
params.put(PAGE_ITEM_POSITION, mCurrPageIndex);
|
||||
EventUtils.sendComponentEvent(currView, EventUtils.EVENT_PAGE_ITEM_WILL_APPEAR, params);
|
||||
if (currView != null) {
|
||||
params.put(PAGE_ITEM_POSITION, mCurrPageIndex);
|
||||
EventUtils.sendComponentEvent(currView, EventUtils.EVENT_PAGE_ITEM_WILL_APPEAR,
|
||||
params);
|
||||
}
|
||||
View lastView = mPager.getViewFromAdapter(mLastPageIndex);
|
||||
params.put(PAGE_ITEM_POSITION, mLastPageIndex);
|
||||
EventUtils.sendComponentEvent(lastView, EventUtils.EVENT_PAGE_ITEM_WILL_DISAPPEAR,
|
||||
params);
|
||||
if (lastView != null) {
|
||||
params.put(PAGE_ITEM_POSITION, mLastPageIndex);
|
||||
EventUtils.sendComponentEvent(lastView, EventUtils.EVENT_PAGE_ITEM_WILL_DISAPPEAR,
|
||||
params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -135,11 +135,14 @@ public class EventUtils {
|
||||
* @param params event extra params object
|
||||
*/
|
||||
@MainThread
|
||||
public static void sendComponentEvent(@NonNull View view, @NonNull String eventName,
|
||||
public static void sendComponentEvent(@Nullable View view, @NonNull String eventName,
|
||||
@Nullable Object params) {
|
||||
// UI component event default disable capture and bubble phase,
|
||||
// can not enable both in native and js.
|
||||
send(view, view.getId(), eventName, params, false, false, EventType.EVENT_TYPE_COMPONENT);
|
||||
if (view != null) {
|
||||
// UI component event default disable capture and bubble phase,
|
||||
// can not enable both in native and js.
|
||||
send(view, view.getId(), eventName, params, false, false,
|
||||
EventType.EVENT_TYPE_COMPONENT);
|
||||
}
|
||||
}
|
||||
|
||||
@MainThread
|
||||
|
||||
Reference in New Issue
Block a user