Skip to content

Commit 136d58b

Browse files
adityasharatfacebook-github-bot
authored andcommitted
Only sets unsets tag if actually set
Summary: Only sets unsets tag if actually set Reviewed By: pentiumao, kingsleyadio Differential Revision: D44170172 fbshipit-source-id: d211b5354254f6ec6f7304771b683201ee47f702
1 parent 6a8b67f commit 136d58b

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

litho-core/src/main/java/com/facebook/litho/LithoViewAttributesExtension.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ static void setViewAttributes(Object content, ViewAttributes attributes, RenderU
214214
}
215215

216216
setViewId(view, attributes.getViewId());
217-
setViewTag(view, attributes.getViewTag());
217+
if (attributes.isTagSet()) {
218+
setViewTag(view, attributes.getViewTag());
219+
}
218220
setViewTags(view, attributes.getViewTags());
219221

220222
setShadowElevation(view, attributes.getShadowElevation());
@@ -297,7 +299,9 @@ static void unsetViewAttributes(
297299
unsetInterceptTouchEventHandler(view);
298300
}
299301

300-
unsetViewTag(view);
302+
if (attributes.isTagSet()) {
303+
unsetViewTag(view);
304+
}
301305
unsetViewTags(view, attributes.getViewTags());
302306

303307
unsetShadowElevation(view, attributes.getShadowElevation());
@@ -550,9 +554,7 @@ private static void setViewId(View view, @IdRes int id) {
550554
}
551555

552556
private static void setViewTag(View view, @Nullable Object viewTag) {
553-
if (viewTag != null) {
554-
view.setTag(viewTag);
555-
}
557+
view.setTag(viewTag);
556558
}
557559

558560
private static void setViewTags(View view, @Nullable SparseArray<Object> viewTags) {

litho-core/src/main/java/com/facebook/litho/ViewAttributes.kt

+9
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class ViewAttributes {
4343
var contentDescription: CharSequence? = null
4444
var viewId: Int = View.NO_ID
4545
var viewTag: Any? = null
46+
set(value) {
47+
field = value
48+
flags = flags or FLAG_VIEW_TAG
49+
}
50+
4651
var transitionName: String? = null
4752
var viewTags: SparseArray<Any>? = null
4853
var outlineProvider: ViewOutlineProvider? = null
@@ -174,6 +179,8 @@ class ViewAttributes {
174179
get() = flags and FLAG_ROTATION_X != 0
175180
val isRotationYSet: Boolean
176181
get() = flags and FLAG_ROTATION_Y != 0
182+
val isTagSet: Boolean
183+
get() = flags and FLAG_VIEW_TAG != 0
177184

178185
fun hasPadding(): Boolean = padding != null
179186

@@ -335,5 +342,7 @@ class ViewAttributes {
335342
private const val FLAG_SHADOW_ELEVATION = 1 shl 12
336343
private const val FLAG_AMBIENT_SHADOW_COLOR = 1 shl 13
337344
private const val FLAG_SPOT_SHADOW_COLOR = 1 shl 14
345+
346+
private const val FLAG_VIEW_TAG = 1 shl 15
338347
}
339348
}

0 commit comments

Comments
 (0)