Skip to content

beep-library/ui-text

Repository files navigation

UISpan.kt
UIText.kt

사용 방법

일반 텍스트 1개만 넣을 때

UIText.StringResource(R.string.map_bottom_sheet_title_not)

Span 효과가 들어간 텍스트를 사용할 때

  • 텍스트를 append한 뒤 속성을 넣고 싶다면 spanOn~ 사용을 하면 된다.
  • 아래 코드에서 spanOn 속성은 appendDynamicString(" $size")에만 적용이 된다.
UIText.Builder()
  .appendStringResource(R.string.map_bottom_sheet_title_all_brands_prefix)
  .appendDynamicString(" $size")
  .spanOnTextColor(R.color.beep_pink)
  .build()

XML에서 사용

<TextView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  app:layout_constraintBottom_toBottomOf="parent"
  app:layout_constraintEnd_toEndOf="parent"
  app:layout_constraintStart_toStartOf="parent"
  app:layout_constraintTop_toTopOf="parent"
  app:setUIText="@{vm.uiText}"
  tools:text="스타벅스에서 사용 가능한 기프티콘이 3개 있어요" />
@BindingAdapter("setUIText")
fun TextView.setUIText(uiText: UIText?) {
    Log.d("TAG", "setUIText: $uiText")
    if (uiText == null) return
    if (uiText.clickable) {
        movementMethod = LinkMovementMethod()
    }
    text = uiText.asString(context)
}

정리

  • Builder 패턴을 사용해서 구현이 됐다.
  • 새로운 Spannable을 적용할 때마다 View나 BindingAdapter에서 직접 만들어야 하는 방식에서 유연하게 변경이 됐다.

적용 결과

About

String에 Span을 추가해서 DataBinding 하기 위해서 만들어봤습니다.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages