Skip to content

Commit

Permalink
Remove redundant Android version checks
Browse files Browse the repository at this point in the history
Summary: As per title - Litho is [now](https://www.internalfb.com/diff/D63837537) minSdk 24.

Reviewed By: kingsleyadio

Differential Revision: D64037320

fbshipit-source-id: 75dec1816436b8c805df2b6cb9815ba315ff9385
  • Loading branch information
zielinskimz authored and facebook-github-bot committed Oct 10, 2024
1 parent df5149a commit 277f1e6
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package com.facebook.litho

import android.os.Build
import android.util.Pair
import android.util.SparseArray
import android.view.View
import androidx.annotation.VisibleForTesting
import com.facebook.litho.CollectionsUtils.isNotNullOrEmpty
import com.facebook.litho.ComponentUtils.handle
import com.facebook.litho.ComponentUtils.rethrow
import com.facebook.litho.drawable.ComparableColorDrawable

/**
* Takes care of dynamic Props
Expand Down Expand Up @@ -241,8 +241,8 @@ class DynamicPropsManager : DynamicValue.OnValueChangeListener<Any?> {
content.background = null
}
KEY_FOREGROUND_COLOR ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && content.foreground != null) {
setViewForeground(content, null)
if (content.foreground != null) {
content.foreground = null
}
}
}
Expand All @@ -261,7 +261,7 @@ class DynamicPropsManager : DynamicValue.OnValueChangeListener<Any?> {
KEY_ROTATION_X -> target.rotationX = resolve(value)
KEY_ROTATION_Y -> target.rotationY = resolve(value)
KEY_BACKGROUND_DRAWABLE -> target.background = resolve(value)
KEY_FOREGROUND_COLOR -> setViewForeground(target, resolve<Int>(value))
KEY_FOREGROUND_COLOR -> target.foreground = ComparableColorDrawable.create(resolve(value))
}
}

Expand Down
9 changes: 2 additions & 7 deletions litho-core/src/main/java/com/facebook/litho/LithoNodeUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.facebook.litho

import android.graphics.drawable.Drawable
import android.os.Build
import android.util.SparseArray
import androidx.core.util.isNotEmpty
import androidx.core.view.ViewCompat
Expand All @@ -28,7 +27,6 @@ import com.facebook.litho.annotations.ImportantForAccessibility
import com.facebook.litho.config.LithoDebugConfigurations
import com.facebook.litho.drawable.BorderColorDrawable
import com.facebook.litho.host.HostViewAttributesCleanupBinder
import com.facebook.litho.utils.VersionedAndroidApis
import com.facebook.rendercore.MountState
import com.facebook.rendercore.RenderUnit
import com.facebook.rendercore.primitives.Primitive
Expand Down Expand Up @@ -217,8 +215,7 @@ object LithoNodeUtils {

/// Only create a foreground output when the component does not mount a View because
// the foreground has already been set in the output of the component.
return if (foreground != null &&
(!node.willMountView || Build.VERSION.SDK_INT < Build.VERSION_CODES.M)) {
return if (foreground != null && (!node.willMountView)) {
createDrawableRenderUnit(node, foreground, width, height, OutputUnitType.FOREGROUND, diffNode)
} else {
null
Expand Down Expand Up @@ -502,9 +499,7 @@ object LithoNodeUtils {
// will be created for backgrounds and foreground.
if (disableBgFgOutputs || !attrs.isHostSpec) {
attrs.background = lithoNode.background
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
VersionedAndroidApis.M.setForeground(attrs, lithoNode.foreground)
}
attrs.foreground = lithoNode.foreground
}
attrs.layoutDirection = lithoNode.layoutDirection
attrs.layerType = lithoNode.layerType
Expand Down
16 changes: 8 additions & 8 deletions litho-core/src/main/java/com/facebook/litho/ViewAttributes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ class ViewAttributes {
setViewStateListAnimator(content, attributes, cloneStateListAnimators)
if (attributes.disableDrawableOutputs) {
setViewBackground(content, attributes)
setViewForeground(content, attributes.foreground)
setViewForeground(content, attributes)

// when background outputs are disabled, they are wrapped by a ComponentHost.
// A background can set the padding of a view, but ComponentHost should not have
Expand All @@ -474,7 +474,7 @@ class ViewAttributes {
// Set view background, if applicable. Do this before padding
// as it otherwise overrides the padding.
setViewBackground(content, attributes)
setViewForeground(content, attributes.foreground)
setViewForeground(content, attributes)
setViewLayoutDirection(content, attributes)
}

Expand Down Expand Up @@ -1050,18 +1050,18 @@ class ViewAttributes {
view.background = drawable
}

private fun unsetViewForeground(view: View, attributes: ViewAttributes) {
private fun setViewForeground(view: View, attributes: ViewAttributes) {
val foreground = attributes.foreground
if (foreground != null) {
unsetForeground(view)
view.foreground = foreground
}
}

fun unsetForeground(view: View) {
check(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
("MountState has a ViewAttributes with foreground however the current Android version doesn't support foreground on Views")
private fun unsetViewForeground(view: View, attributes: ViewAttributes) {
val foreground = attributes.foreground
if (foreground != null) {
view.foreground = null
}
view.foreground = null
}

private fun setViewLayoutDirection(view: View, attributes: ViewAttributes) {
Expand Down
42 changes: 0 additions & 42 deletions litho-core/src/main/java/com/facebook/litho/ViewUtils.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.facebook.litho.config

import android.os.Build
import com.facebook.litho.BuildConfig
import com.facebook.litho.ComponentHost
import com.facebook.litho.ComponentHost.UnsafeModificationPolicy
Expand Down Expand Up @@ -194,11 +193,6 @@ internal constructor(
/** Indicates that the incremental mount helper is required for this build. */
@JvmField val USE_INCREMENTAL_MOUNT_HELPER: Boolean = BuildConfig.USE_INCREMENTAL_MOUNT_HELPER

/** Whether we need to account for lack of synchronization while accessing Themes. */
@JvmField
val NEEDS_THEME_SYNCHRONIZATION: Boolean =
Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1

/** The default priority for threads that perform background layout calculations. */
@JvmField var DEFAULT_BACKGROUND_THREAD_PRIORITY: Int = 5

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
package com.facebook.litho.host

import android.content.Context
import android.os.Build
import android.view.View
import android.view.ViewOutlineProvider
import androidx.core.view.ViewCompat
Expand All @@ -14,7 +13,6 @@ import com.facebook.litho.ViewAttributes.Companion.unsetAmbientShadowColor
import com.facebook.litho.ViewAttributes.Companion.unsetClickHandler
import com.facebook.litho.ViewAttributes.Companion.unsetContentDescription
import com.facebook.litho.ViewAttributes.Companion.unsetFocusChangeHandler
import com.facebook.litho.ViewAttributes.Companion.unsetForeground
import com.facebook.litho.ViewAttributes.Companion.unsetInterceptTouchEventHandler
import com.facebook.litho.ViewAttributes.Companion.unsetLongClickHandler
import com.facebook.litho.ViewAttributes.Companion.unsetSpotShadowColor
Expand Down Expand Up @@ -74,12 +72,8 @@ private fun unsetAllViewAttributes(content: Host) {
ViewCompat.setElevation(content, 0f)
unsetAmbientShadowColor(content, -1)
unsetSpotShadowColor(content, -1)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
content.outlineProvider = ViewOutlineProvider.BACKGROUND
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
content.clipToOutline = false
}
content.outlineProvider = ViewOutlineProvider.BACKGROUND
content.clipToOutline = false
content.clipChildren = true
unsetContentDescription(content)
unsetTooltipText(content)
Expand All @@ -94,11 +88,11 @@ private fun unsetAllViewAttributes(content: Host) {
content.isFocusable = false
content.isEnabled = true
content.isSelected = false
content.foreground = null
ViewCompat.setKeyboardNavigationCluster(content, false)
ViewCompat.setImportantForAccessibility(content, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO)
unsetAccessibilityDelegate(content)
setBackgroundCompat(content, null)
unsetForeground(content)
unsetViewLayoutDirection(content)
content.setLayerType(View.LAYER_TYPE_NONE, null)
ViewCompat.setSystemGestureExclusionRects(content, emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,17 @@
package com.facebook.litho.utils

import android.graphics.Paint
import android.graphics.drawable.Drawable
import android.icu.text.BreakIterator
import android.os.Build
import android.text.Layout
import android.view.View
import android.widget.EditText
import androidx.annotation.ColorInt
import androidx.annotation.DoNotInline
import androidx.annotation.DrawableRes
import androidx.annotation.RequiresApi
import com.facebook.litho.ViewAttributes

object VersionedAndroidApis {

@RequiresApi(Build.VERSION_CODES.M)
object M {
@DoNotInline
fun setForeground(attrs: ViewAttributes, foreground: Drawable?) {
attrs.foreground = foreground
}

@DoNotInline
@JvmStatic
fun getEllipsisOffsetFromPaintAdvance(
layout: Layout,
text: CharSequence?,
isRtl: Boolean,
line: Int,
advance: Float
): Int {
val paint: Paint = layout.paint
val lineStart = layout.getLineStart(line)
val lineEnd = layout.getLineEnd(line)
return paint.getOffsetForAdvance(text, lineStart, lineEnd, lineStart, lineEnd, isRtl, advance)
}
}

@RequiresApi(Build.VERSION_CODES.P)
object P {
@DoNotInline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.facebook.litho.testing.viewtree;

import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.litho.ComponentHost;
Expand Down Expand Up @@ -131,10 +130,8 @@ private static boolean satisfiesPredicate(
if (host.getBackground() != null) {
drawables.add(host.getBackground());
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (host.getForeground() != null) {
drawables.add(host.getForeground());
}
if (host.getForeground() != null) {
drawables.add(host.getForeground());
}
for (final Drawable drawable : drawables) {
if (predicate.apply(drawable)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.facebook.litho.testing.viewtree;

import android.graphics.drawable.Drawable;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
Expand Down Expand Up @@ -84,10 +83,8 @@ public String apply(@Nullable View input) {
if (host.getBackground() != null) {
drawables.add(String.valueOf(host.getBackground()));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (host.getForeground() != null) {
drawables.add(String.valueOf(host.getForeground()));
}
if (host.getForeground() != null) {
drawables.add(String.valueOf(host.getForeground()));
}
return String.format(
"Found drawables: \"%s\", view is %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static android.graphics.Color.TRANSPARENT;
import static android.os.Build.VERSION.SDK_INT;
import static android.os.Build.VERSION_CODES.M;
import static android.view.View.TEXT_ALIGNMENT_GRAVITY;

import android.content.Context;
Expand Down Expand Up @@ -920,10 +919,7 @@ static void onBindEditText(
EventHandler textPastedEventHandler) {
editText.attachWatchers(textWatchers);
editText.setCustomSelectionActionModeCallback(selectionActionModeCallback);
if (SDK_INT >= M) {
editText.setCustomInsertionActionModeCallback(insertionActionModeCallback);
}

editText.setCustomInsertionActionModeCallback(insertionActionModeCallback);
editText.setComponentContext(c);
editText.setTextChangedEventHandler(textChangedEventHandler);
editText.setSelectionChangedEventHandler(selectionChangedEventHandler);
Expand Down Expand Up @@ -964,9 +960,7 @@ static void onUnbind(final ComponentContext c, EditTextWithEventHandlers editTex
editText.setEditorActionEventHandler(null);
editText.setInputConnectionEventHandler(null);
editText.setCustomSelectionActionModeCallback(null);
if (SDK_INT >= M) {
editText.setCustomInsertionActionModeCallback(null);
}
editText.setCustomInsertionActionModeCallback(null);
editText.setTextPastedEventHandler(null);
}

Expand Down Expand Up @@ -1215,16 +1209,6 @@ public EditTextWithEventHandlers(Context context) {
this.setOnEditorActionListener(this);
}

@Override
public void requestLayout() {
// TextInputSpec$ForMeasureEditText.setText in API23 causing relayout for
// EditTextWithEventHandlers https://fburl.com/mgq76t3l
if (SDK_INT == M && !ThreadUtils.isMainThread()) {
return;
}
super.requestLayout();
}

@Override
protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
super.onTextChanged(text, start, lengthBefore, lengthAfter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
Expand Down Expand Up @@ -845,15 +846,12 @@ private static CharSequence truncateText(
ellipsisTarget = customEllipsisTextWidth;
}
// Get character offset number corresponding to that X position:

int ellipsisOffset;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
ellipsisOffset =
VersionedAndroidApis.M.getEllipsisOffsetFromPaintAdvance(
newLayout, text, isRtl, ellipsizedLineNumber, ellipsisTarget);
} else {
ellipsisOffset = newLayout.getOffsetForHorizontal(ellipsizedLineNumber, ellipsisTarget);
}
final Paint paint = newLayout.getPaint();
final int lineStart = newLayout.getLineStart(ellipsizedLineNumber);
final int lineEnd = newLayout.getLineEnd(ellipsizedLineNumber);
int ellipsisOffset =
paint.getOffsetForAdvance(
text, lineStart, lineEnd, lineStart, lineEnd, isRtl, ellipsisTarget);

if (ellipsisOffset > 0) {
// getOffsetForHorizontal returns the closest character, but we need to guarantee no
Expand Down
Loading

0 comments on commit 277f1e6

Please sign in to comment.