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

Fix(Android): the GridView crashes when scrolling and closing the screen #174

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions android/src/main/java/com/giphyreactnativesdk/RTNGiphyGridView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.giphyreactnativesdk

import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.children
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.ThemedReactContext
import com.giphy.sdk.core.models.enums.MediaType
Expand Down Expand Up @@ -38,6 +40,18 @@ class RTNGiphyGridView @JvmOverloads constructor(
addView(gridView)
}

fun onDropViewInstance() {
gridView.children.forEach {
(it as? ViewGroup)?.let { vg ->
vg.removeAllViews()
vg.clearDisappearingChildren()
}
}
gridView.removeAllViews()
gridView.clearDisappearingChildren()
removeAllViews()
}

override fun requestLayout() {
super.requestLayout()
post(measureAndLayout)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class RTNGiphyGridViewManager :
return view
}

override fun onDropViewInstance(view: RTNGiphyGridView) {
view.onDropViewInstance()
super.onDropViewInstance(view)
}

@ReactProp(name = "theme")
override fun setTheme(view: RTNGiphyGridView?, value: String?) {
if (value.isNullOrEmpty()) {
Expand Down
Loading