Skip to content

[BUG] app:readMoreMaxLine이 1일 때 IndexOutOfBoundException이 발생하는 문제 #5

@skfo763

Description

@skfo763

ReadMoreTextView.kt 의 120번째 라인

private fun getAdjustCutCount(maxLine: Int, readMoreText: String): Int {

        val lastLineStartIndex = layout.getLineVisibleEnd(maxLine - 2) + 1
        val lastLineEndIndex = layout.getLineVisibleEnd(maxLine - 1)
        val lastLineText = text.substring(lastLineStartIndex, lastLineEndIndex)

        val bounds = Rect()
        paint.getTextBounds(lastLineText, 0, lastLineText.length, bounds)
       ...
}

에서 layout.getLineVisibleEnd(maxLine-2) + 1 코드로 인해서,
maxLine 값에 1이 할당되면 getLineVisibleEnd 함수의 결과로 -1이 리턴되어

maxLine 인자는 readMoreMaxLine 속성이던데, 여기에 1이 들어가면 크래시가 나는 것 같아 이슈 올립니다.
이 문제가 의도된것인지 코멘트 남겨주시면 감사하겠습니다.

현재 수정하고자 하는 방향은, 122번~123번 라인을 다음과 같이 수정하는 것입니다.

// before
val lastLineStartIndex = layout.getLineVisibleEnd(maxLine - 2) + 1
val lastLineEndIndex = layout.getLineVisibleEnd(maxLine - 1)
val lastLineText = text.substring(lastLineStartIndex, lastLineEndIndex)


// after
val lastLineStartIndex = layout.getLineVisibleEnd(kotlin.math.max(maxLine - 2, 0)) + 1
val lastLineEndIndex = layout.getLineVisibleEnd(kotlin.math.max(maxLine - 1, 1))
val lastLineText = text.substring(lastLineStartIndex, lastLineEndIndex)

이 수정방향과 관련되어서도 코멘트 남겨주시면 감사하겠습니다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions