Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifier.glideNode has a error. #5272

Closed
lyh8577 opened this issue Aug 31, 2023 · 1 comment · Fixed by #5276
Closed

Modifier.glideNode has a error. #5272

lyh8577 opened this issue Aug 31, 2023 · 1 comment · Fixed by #5276
Labels

Comments

@lyh8577
Copy link

lyh8577 commented Aug 31, 2023

Glide Version:
dependencies {
implementation("com.github.bumptech.glide:glide:4.16.0")
ksp("com.github.bumptech.glide:ksp:4.16.0")
}

Integration libraries:
dependencies {
implementation("com.github.bumptech.glide:okhttp3-integration:4.16.0")
implementation("com.github.bumptech.glide:compose:1.0.0-alpha.5")
}

Device/Android Version:
Android Emulator API 34

Issue details / Repro steps / Use case background:
If set Modifier.padding(xxx) for GlideSubcomposition, the padding applied twice。

Glide load line / GlideModule (if any) / list Adapter code (if any):

@Preview(showSystemUi = true)
@OptIn(ExperimentalGlideComposeApi::class)
@Composable
fun SimpleGlide() {
    var lastSize by remember { mutableStateOf(Size.Unspecified) }

    Surface {
        GlideSubcomposition(
            model = null,
            modifier = Modifier
                .fillMaxWidth()
                .aspectRatio(1f)
                .drawBehind {
                    Log.d("SimpleGlide",size.toString())
                    if (lastSize.isUnspecified) {
                        lastSize = this.size
                        drawRect(Color.Blue)
                    } else if (lastSize != this.size) {
                        drawRect(Color.Red)
                    }else{
                        drawRect(Color.Blue)
                    }
                }
                .padding(40.dp),
        ) {
            when (state) {
                RequestState.Failure -> Image(
                    imageVector = Icons.Default.MusicNote,
                    contentDescription = "placeholder",
                    modifier = Modifier.fillMaxSize()
                )

                RequestState.Loading -> Spacer(modifier = Modifier.shimmerPlaceholder(visible = true))
                is RequestState.Success -> Image(painter = painter, contentDescription = null)
            }
        }
    }
}

Stack trace / LogCat:

2023-08-31 13:18:32.354  8397-8397  SimpleGlide             com.xxx.development      D  Size(1080.0, 1080.0)
2023-08-31 13:18:32.354  8397-8397  SimpleGlide             com.xxx.development      D  Size(870.0, 870.0)
2023-08-31 13:18:32.480  8397-8397  SimpleGlide             com.xxx.development      D  Size(1080.0, 1080.0)
2023-08-31 13:18:32.481  8397-8397  SimpleGlide             com.xxx.development      D  Size(870.0, 870.0)

Screenshot_20230831_131858

compose library code:

@ExperimentalGlideComposeApi
internal fun Modifier.glideNode(
  requestBuilder: RequestBuilder<Drawable>,
  contentDescription: String? = null,
  alignment: Alignment? = null,
  contentScale: ContentScale? = null,
  alpha: Float? = null,
  colorFilter: ColorFilter? = null,
  transitionFactory: Transition.Factory? = null,
  requestListener: RequestListener? = null,
  draw: Boolean? = null,
): Modifier {
  return this then GlideNodeElement(
    requestBuilder,
    contentScale ?: ContentScale.None,
    alignment ?: Alignment.Center,
    alpha,
    colorFilter,
    requestListener,
    draw,
    transitionFactory,
  ) then
      clipToBounds() then
      if (contentDescription != null) {
        semantics {
          this@semantics.contentDescription = contentDescription
          role = Role.Image
        }
      } else {
        Modifier
      }
}

The then clipToBounds() is equivalent to then this.clipToBounds(), should use .clipToBounds() or Modifier.clipToBounds().
The modifier **semantics{} ** is also a similar error.

@sjudd
Copy link
Collaborator

sjudd commented Sep 3, 2023

Thanks for the report, I really appreciate the detail!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants