Skip to content

Commit

Permalink
fix(android): sendComponentEvent with view==null crash
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 authored and siguangli committed Sep 14, 2023
1 parent 15b16a8 commit d73dc28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ public void onPageSelected(int position) {
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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ public enum EventType {
* @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
Expand Down

0 comments on commit d73dc28

Please sign in to comment.