Add better text reflow as font changes.
This commit is contained in:
parent
7c45fb6c17
commit
4dca554967
5 changed files with 20 additions and 13 deletions
|
@ -5,9 +5,11 @@ import android.text.Editable
|
|||
import android.text.TextWatcher
|
||||
import android.util.AttributeSet
|
||||
import android.util.TypedValue
|
||||
import androidx.core.content.res.use
|
||||
import androidx.core.view.doOnNextLayout
|
||||
import org.signal.core.util.DimensionUnit
|
||||
import org.signal.core.util.EditTextUtil
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiEditText
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.max
|
||||
|
@ -50,7 +52,16 @@ class AutoSizeEmojiEditText @JvmOverloads constructor(
|
|||
|
||||
init {
|
||||
EditTextUtil.addGraphemeClusterLimitFilter(this, 700)
|
||||
addTextChangedListener(watcher)
|
||||
|
||||
if (attrs != null) {
|
||||
context.obtainStyledAttributes(attrs, R.styleable.AutoSizeEmojiEditText).use { typedArray ->
|
||||
if (typedArray.getBoolean(R.styleable.AutoSizeEmojiEditText_aseet_EnforceLineCount, true)) {
|
||||
addTextChangedListener(watcher)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
addTextChangedListener(watcher)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
|
@ -58,12 +69,6 @@ class AutoSizeEmojiEditText @JvmOverloads constructor(
|
|||
|
||||
if (isInEditMode) return
|
||||
|
||||
if (checkCountAndAddListener()) {
|
||||
// TODO [stories] infinite measure loop when font change pushes us over the line count limit
|
||||
measure(widthMeasureSpec, heightMeasureSpec)
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
val operation = getNextAutoSizeOperation()
|
||||
val newSize = when (operation) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import androidx.annotation.ColorInt
|
|||
import androidx.annotation.IntRange
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
import kotlinx.parcelize.Parcelize
|
||||
import org.signal.core.util.DimensionUnit
|
||||
import org.thoughtcrime.securesms.conversation.colors.ChatColors
|
||||
import org.thoughtcrime.securesms.fonts.TextFont
|
||||
import org.thoughtcrime.securesms.scribbles.HSVColorSlider
|
||||
|
@ -18,7 +17,6 @@ data class TextStoryPostCreationState(
|
|||
val textColor: Int = HSVColorSlider.getLastColor(),
|
||||
val textColorStyle: TextColorStyle = TextColorStyle.NO_BACKGROUND,
|
||||
val textAlignment: TextAlignment = if (FeatureFlags.storiesTextFunctions()) TextAlignment.START else TextAlignment.CENTER,
|
||||
val textSize: Float = DimensionUnit.DP.toPixels(32f),
|
||||
val textFont: TextFont = TextFont.REGULAR,
|
||||
@IntRange(from = 0, to = 100) val textScale: Int = 50,
|
||||
val backgroundColor: ChatColors = TextStoryBackgroundColors.getInitialBackgroundColor(),
|
||||
|
|
|
@ -130,7 +130,6 @@ class StoryTextPostView @JvmOverloads constructor(
|
|||
)
|
||||
|
||||
setTextColor(state.textForegroundColor)
|
||||
setTextSize(state.textSize)
|
||||
setTextBackgroundColor(state.textBackgroundColor)
|
||||
setTextGravity(state.textAlignment)
|
||||
setTextScale(state.textScale)
|
||||
|
|
|
@ -12,9 +12,10 @@
|
|||
android:layout_height="match_parent"
|
||||
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.Signal.Story.Text" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
||||
<org.thoughtcrime.securesms.mediasend.v2.text.AutoSizeEmojiEditText
|
||||
android:focusable="false"
|
||||
android:id="@+id/text_story_post_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:background="@drawable/rounded_rectangle_secondary_18"
|
||||
|
@ -25,13 +26,13 @@
|
|||
android:text="@string/TextStoryPostCreationFragment__tap_to_add_text"
|
||||
android:textAppearance="@style/TextAppearance.Signal.Body1.Bold"
|
||||
android:textColor="@color/core_white"
|
||||
android:textSize="32dp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constrainedWidth="true"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:aseet_EnforceLineCount="false"
|
||||
tools:ignore="SpUsage"
|
||||
tools:text="THIS IS SOME TEXT THAT I AM ENTERING" />
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
|
||||
<attr name="contact_filter_toolbar_icon_tint" format="color" />
|
||||
|
||||
<declare-styleable name="AutoSizeEmojiEditText">
|
||||
<attr name="aseet_EnforceLineCount" format="boolean" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="SegmentedProgressBar">
|
||||
<attr name="totalSegments" format="integer" />
|
||||
<attr name="timePerSegment" format="integer" />
|
||||
|
|
Loading…
Add table
Reference in a new issue