Skip to content

Commit

Permalink
fix(androi): commit fragments transaction only once after wrapping vi…
Browse files Browse the repository at this point in the history
…ew being attached to a window

prevent crash when using ti.map inside a ListView

ref TIMOB-28583 fix tidev#13243
  • Loading branch information
drauggres committed Feb 8, 2022
1 parent 79a94f7 commit 64270c5
Showing 1 changed file with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,30 @@ public TiUIFragment(TiViewProxy proxy, Activity activity)
fragment = createFragment();
} else {
TiCompositeLayout container = new TiCompositeLayout(activity, proxy) {
private boolean transactionCommited = false;
@Override
public boolean dispatchTouchEvent(MotionEvent ev)
{
return interceptTouchEvent(ev) || super.dispatchTouchEvent(ev);
}

@Override
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
if (!transactionCommited) {
transactionCommited = true;
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 +77,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 64270c5

Please sign in to comment.