Skip to content

Commit

Permalink
feat(android): implement host activity lifecycle
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed Apr 2, 2024
1 parent b5ea94c commit 666d429
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class NaverMapViewManager : NaverMapViewManagerSpec<NaverMapComposeView>() {
}

override fun createViewInstance(context: ThemedReactContext): NaverMapComposeView {
return NaverMapComposeView(context, NaverMapOptions())
return NaverMapComposeView(context, NaverMapOptions()).also {
context.addLifecycleEventListener(it)
}
}

override fun onDropViewInstance(view: NaverMapComposeView) {
super.onDropViewInstance(view)
view.onDropViewInstance()
view.reactContext.removeLifecycleEventListener(view)
}

override fun setNightMode(view: NaverMapComposeView?, value: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import android.os.Bundle
import android.view.Choreographer
import android.view.Choreographer.FrameCallback
import android.widget.FrameLayout
import com.facebook.react.bridge.LifecycleEventListener
import com.facebook.react.uimanager.ThemedReactContext
import com.naver.maps.map.NaverMapOptions

@SuppressLint("ViewConstructor")
class NaverMapComposeView(private val context: ThemedReactContext, private val mapOptions: NaverMapOptions) :
FrameLayout(context) {
class NaverMapComposeView(val reactContext: ThemedReactContext, private val mapOptions: NaverMapOptions) :
FrameLayout(reactContext), LifecycleEventListener {
private var mapView: NaverMapView? = null
private var savedState: Bundle? = Bundle()

init {
mapView = NaverMapView(context, mapOptions)
mapView = NaverMapView(reactContext, mapOptions)
addView(mapView)
}

Expand Down Expand Up @@ -68,4 +69,16 @@ class NaverMapComposeView(private val context: ThemedReactContext, private val m
child.layout(0, 0, child.measuredWidth, child.measuredHeight)
}
}

override fun onHostResume() {
mapView?.onResume()
}

override fun onHostPause() {
mapView?.onPause()
}

override fun onHostDestroy() {
mapView?.onDestroy()
}
}

0 comments on commit 666d429

Please sign in to comment.