Skip to content

Commit

Permalink
fix(android): handle "attached to window" event in TiUIFragment
Browse files Browse the repository at this point in the history
prevent crash when using ti.map inside a ListView

ref TIMOB-28583 fix tidev#13243
  • Loading branch information
drauggres committed Feb 3, 2022
1 parent 3c0bda7 commit 9b3f4cb
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ public boolean dispatchTouchEvent(MotionEvent ev)
{
return interceptTouchEvent(ev) || super.dispatchTouchEvent(ev);
}

@Override
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
FragmentManager manager = ((FragmentActivity) getContext()).getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.runOnCommit(onCommitRunnable);
fragment = createFragment();
transaction.add(getId(), fragment);
transaction.commitAllowingStateLoss();
}
};
container.setId(View.generateViewId());
setNativeView(container);

FragmentManager manager = ((FragmentActivity) activity).getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.runOnCommit(onCommitRunnable);
fragment = createFragment();
transaction.add(container.getId(), fragment);
transaction.commitAllowingStateLoss();
}
}

Expand All @@ -68,6 +73,9 @@ public void run()

public void realizeFragmentViews()
{
if (childrenToRealize == null) {
return;
}
for (TiUIView child : childrenToRealize) {
// Draw the views
((ViewGroup) getNativeView()).addView(child.getOuterView(), child.getLayoutParams());
Expand Down

0 comments on commit 9b3f4cb

Please sign in to comment.