Skip to content

Fix: #135 #153

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

Merged
merged 5 commits into from
Jan 5, 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class SdkInitializer(
try {
if (clientId != null) initializeMapSdk(context, clientId, isGov)
if (setAuthFailedListener) setOnAuthFailedListener()
val sendPayload = mapOf("androidSdkVersion" to androidSdkVersion)
val sendPayload = mapOf("androidSdkVersion" to Build.VERSION.SDK_INT)
onSuccess(sendPayload)
} catch (e: NaverMapSdk.AuthFailedException) {
onFailure(e)
Expand All @@ -63,8 +63,4 @@ internal class SdkInitializer(
)
)
}

companion object {
private val androidSdkVersion: Int get() = Build.VERSION.SDK_INT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package dev.note11.flutter_naver_map.flutter_naver_map.view
import android.app.Activity
import android.app.Application
import android.content.ComponentCallbacks
import android.content.Context
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.view.View
import com.naver.maps.map.MapView
Expand All @@ -21,20 +23,24 @@ import io.flutter.plugin.platform.PlatformView

internal class NaverMapView(
private val activity: Activity,
private val flutterProvidedContext: Context,
private val naverMapViewOptions: NaverMapViewOptions,
private val channel: MethodChannel,
private val overlayController: OverlayHandler,
) : PlatformView, Application.ActivityLifecycleCallbacks, ComponentCallbacks {

private lateinit var naverMap: NaverMap
private lateinit var naverMapControlSender: NaverMapControlSender
private val mapView = MapView(activity, naverMapViewOptions.naverMapOptions).apply {
setTempMethodCallHandler()
getMapAsync { naverMap ->
[email protected] = naverMap
onMapReady()
private val mapView =
MapView(flutterProvidedContext, naverMapViewOptions.naverMapOptions.apply {
useTextureView(Build.VERSION.SDK_INT <= 29)
}).apply {
setTempMethodCallHandler()
getMapAsync { naverMap ->
[email protected] = naverMap
onMapReady()
}
}
}
private var isListenerRegistered = false
private var rawNaverMapOptionTempCache: Any? = null

Expand All @@ -60,7 +66,7 @@ internal class NaverMapView(

private fun initializeMapController() {
naverMapControlSender = NaverMapController(
naverMap, channel, activity.applicationContext, overlayController
naverMap, channel, flutterProvidedContext, overlayController
).apply {
rawNaverMapOptionTempCache?.let { updateOptions(it.asMap()) {} }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ internal class NaverMapViewFactory(

return NaverMapView(
activity = activity,
flutterProvidedContext = context,
naverMapViewOptions = options,
channel = channel,
overlayController = overlayController,
Expand Down
19 changes: 6 additions & 13 deletions lib/src/widget/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@ class _PlatformViewCreator {
hitTestBehavior: hitTestBehavior,
),
onCreatePlatformView: (params) {
// issues
// 1. android 5.0 (API 21) ~ android 7.1 (API 25) render issue (GLSurfaceView rendered under flutter view)
// -> ExpensiveAndroidView, TextureSurfaceComposition (SurfaceAndroidView).
// 2. "Unexpected platform view context for view ID 0;" issue. (+ minimum API 23)
// -> AndroidView (virtual display)
// RenderView(Impl Android Side), Display Mode
// API 23 ~ 29 : TextureView, Texture Layer Hybrid Composition.
// API 30 ~ : GLSurfaceView, Hybrid Composition (TLHC cause issue: flutter#98865)

// initAndroidView : auto detect.
// but Android 10 or higher, use TextureSurfaceComposition.

const hybridView = PlatformViewsService.initExpensiveAndroidView;
// const autoView = PlatformViewsService.initAndroidView;
const autoView = PlatformViewsService.initSurfaceAndroidView;

final usingView = androidSdkVersion! >= 26 ? hybridView : autoView;
final usingView = androidSdkVersion! <= 29
? PlatformViewsService.initAndroidView
: PlatformViewsService.initExpensiveAndroidView;

final view = usingView.call(
id: params.id,
Expand Down