<commit_before>/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.facebook.litho.kotlin.widget

import android.graphics.Color
import android.graphics.Typeface
import android.graphics.Typeface.DEFAULT
import android.graphics.Typeface.NORMAL
import android.text.TextUtils
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.StyleRes
import androidx.core.text.TextDirectionHeuristicCompat
import com.facebook.litho.Dimen
import com.facebook.litho.DynamicValue
import com.facebook.litho.Handle
import com.facebook.litho.ResourcesScope
import com.facebook.litho.Style
import com.facebook.litho.dp
import com.facebook.litho.kotlinStyle
import com.facebook.litho.sp
import com.facebook.litho.widget.Text
import com.facebook.litho.widget.TextAlignment
import com.facebook.litho.widget.VerticalGravity

/**
 * Temporary builder function for creating [TextSpec] components. In the future it will either be
 * auto-generated or modified to have the final set of parameters.
 */
@Suppress("NOTHING_TO_INLINE", "FunctionName")
inline fun ResourcesScope.Text(
    text: CharSequence?,
    style: Style? = null,
    @ColorInt textColor: Int = Color.BLACK,
    textSize: Dimen = 14.sp,
    textStyle: Int = NORMAL,
    typeface: Typeface? = DEFAULT,
    @ColorInt shadowColor: Int = Color.GRAY,
    shadowRadius: Dimen = 0.dp,
    alignment: TextAlignment = TextAlignment.TEXT_START,
    verticalGravity: VerticalGravity = VerticalGravity.TOP,
    isSingleLine: Boolean = false,
    ellipsize: TextUtils.TruncateAt? = null,
    lineSpacingMultiplier: Float = 1f,
    lineHeight: Dimen? = null,
    extraSpacing: Dimen? = null,
    letterSpacing: Float = 0f,
    minLines: Int = 0,
    maxLines: Int = Int.MAX_VALUE,
    includeFontPadding: Boolean = true,
    accessibleClickableSpans: Boolean = false,
    clipToBounds: Boolean = true,
    handle: Handle? = null,
    customEllipsisText: CharSequence? = null,
    @ColorInt backgroundColor: Int? = null,
    @ColorInt highlightColor: Int? = null,
    textDirection: TextDirectionHeuristicCompat? = null,
    @AttrRes defStyleAttr: Int = 0,
    @StyleRes defStyleRes: Int = 0,
    dynamicTextColor: DynamicValue<Int>? = null,
): Text =
    Text.create(context, defStyleAttr, defStyleRes)
        .text(text)
        .dynamicTextColor(dynamicTextColor)
        .textColor(textColor)
        .textSizePx(textSize.toPixels())
        .textStyle(textStyle)
        .typeface(typeface)
        .shadowColor(shadowColor)
        .shadowRadiusPx(shadowRadius.toPixels().toFloat())
        .alignment(alignment)
        .verticalGravity(verticalGravity)
        .spacingMultiplier(lineSpacingMultiplier)
        .isSingleLine(isSingleLine)
        .minLines(minLines)
        .maxLines(maxLines)
        .apply { lineHeight?.let { lineHeightPx(it.toPixels().toFloat()) } }
        .apply { extraSpacing?.let { extraSpacingPx(it.toPixels().toFloat()) } }<commit_msg>Add breakStrategy prop to Kotlin Text component<commit_after>/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.facebook.litho.kotlin.widget

import android.graphics.Color
import android.graphics.Typeface
import android.graphics.Typeface.DEFAULT
import android.graphics.Typeface.NORMAL
import android.text.TextUtils
import androidx.annotation.AttrRes
import androidx.annotation.ColorInt
import androidx.annotation.StyleRes
import androidx.core.text.TextDirectionHeuristicCompat
import com.facebook.litho.Dimen
import com.facebook.litho.DynamicValue
import com.facebook.litho.Handle
import com.facebook.litho.ResourcesScope
import com.facebook.litho.Style
import com.facebook.litho.dp
import com.facebook.litho.kotlinStyle
import com.facebook.litho.sp
import com.facebook.litho.widget.Text
import com.facebook.litho.widget.TextAlignment
import com.facebook.litho.widget.VerticalGravity

/**
 * Temporary builder function for creating [TextSpec] components. In the future it will either be
 * auto-generated or modified to have the final set of parameters.
 */
@Suppress("NOTHING_TO_INLINE", "FunctionName")
inline fun ResourcesScope.Text(
    text: CharSequence?,
    style: Style? = null,
    @ColorInt textColor: Int = Color.BLACK,
    textSize: Dimen = 14.sp,
    textStyle: Int = NORMAL,
    typeface: Typeface? = DEFAULT,
    @ColorInt shadowColor: Int = Color.GRAY,
    shadowRadius: Dimen = 0.dp,
    alignment: TextAlignment = TextAlignment.TEXT_START,
    breakStrategy: Int = 0,
    verticalGravity: VerticalGravity = VerticalGravity.TOP,
    isSingleLine: Boolean = false,
    ellipsize: TextUtils.TruncateAt? = null,
    lineSpacingMultiplier: Float = 1f,
    lineHeight: Dimen? = null,
    extraSpacing: Dimen? = null,
    letterSpacing: Float = 0f,
    minLines: Int = 0,
    maxLines: Int = Int.MAX_VALUE,
    includeFontPadding: Boolean = true,
    accessibleClickableSpans: Boolean = false,
    clipToBounds: Boolean = true,
    handle: Handle? = null,
    customEllipsisText: CharSequence? = null,
    @ColorInt backgroundColor: Int? = null,
    @ColorInt highlightColor: Int? = null,
    textDirection: TextDirectionHeuristicCompat? = null,
    @AttrRes defStyleAttr: Int = 0,
    @StyleRes defStyleRes: Int = 0,
    dynamicTextColor: DynamicValue<Int>? = null,
): Text =
    Text.create(context, defStyleAttr, defStyleRes)
        .text(text)
        .dynamicTextColor(dynamicTextColor)
        .textColor(textColor)
        .textSizePx(textSize.toPixels())
        .textStyle(textStyle)
        .typeface(typeface)
        .shadowColor(shadowColor)
        .shadowRadiusPx(shadowRadius.toPixels().toFloat())
        .alignment(alignment)
        .breakStrategy(breakStrategy)
        .verticalGravity(verticalGravity)
        .spacingMultiplier(lineSpacingMultiplier)
        .isSingleLine(isSingleLine)
        .minLines(minLines)
        .maxLines(maxLines)
        .apply { lineHeight?.let { lineHeightPx(it.toPixels().toFloat()) } }
        .apply { extraSpacing?.let { extraSpacingPx(it.toPixels().toFloat()) } }
{'fraction_non_alphanumeric': 0.09473094170403587, 'fraction_numerical': 0.0035033632286995517, 'mean_word_length': 3.8917066483893077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4743032', 'n_tokens_mistral': 2130, 'n_tokens_neox': 2100, 'n_words': 556}