Skip to content

Commit 0838db2

Browse files
authored
fix(android): commit fragments transaction only once after wrapping view being attached to a window (#13263)
prevent crash when using ti.map inside a ListView ref TIMOB-28583 fix#13243
1 parent b30de10 commit 0838db2

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

android/titanium/src/java/org/appcelerator/titanium/view/TiUIFragment.java

+19-7
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,30 @@ public TiUIFragment(TiViewProxy proxy, Activity activity)
3838
fragment = createFragment();
3939
} else {
4040
TiCompositeLayoutcontainer = newTiCompositeLayout(activity, proxy) {
41+
privatebooleantransactionCommitted = false;
4142
@Override
4243
publicbooleandispatchTouchEvent(MotionEventev)
4344
{
4445
returninterceptTouchEvent(ev) || super.dispatchTouchEvent(ev);
4546
}
47+
48+
@Override
49+
protectedvoidonAttachedToWindow()
50+
{
51+
super.onAttachedToWindow();
52+
if (!transactionCommitted) {
53+
transactionCommitted = true;
54+
FragmentManagermanager = ((FragmentActivity) getContext()).getSupportFragmentManager();
55+
FragmentTransactiontransaction = manager.beginTransaction();
56+
transaction.runOnCommit(onCommitRunnable);
57+
fragment = createFragment();
58+
transaction.add(getId(), fragment);
59+
transaction.commitAllowingStateLoss();
60+
}
61+
}
4662
};
4763
container.setId(View.generateViewId());
4864
setNativeView(container);
49-
50-
FragmentManagermanager = ((FragmentActivity) activity).getSupportFragmentManager();
51-
FragmentTransactiontransaction = manager.beginTransaction();
52-
transaction.runOnCommit(onCommitRunnable);
53-
fragment = createFragment();
54-
transaction.add(container.getId(), fragment);
55-
transaction.commitAllowingStateLoss();
5665
}
5766
}
5867

@@ -68,6 +77,9 @@ public void run()
6877

6978
publicvoidrealizeFragmentViews()
7079
{
80+
if (childrenToRealize == null) {
81+
return;
82+
}
7183
for (TiUIViewchild : childrenToRealize) {
7284
// Draw the views
7385
((ViewGroup) getNativeView()).addView(child.getOuterView(), child.getLayoutParams());

0 commit comments

Comments
 (0)
close