Comments (1)
The problem is in ViewAttachmentManager. It adds FrameLayout to WindowManager and non of them have reference on LifecycleOwner.
Here is workaround I created temporary. Replace lib's ViewAttachmentManager on this one:
`import android.content.Context
import android.graphics.PixelFormat
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.FrameLayout
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.setViewTreeLifecycleOwner
import androidx.lifecycle.setViewTreeViewModelStoreOwner
import androidx.savedstate.SavedStateRegistryOwner
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
import com.google.ar.sceneform.rendering.ViewAttachmentManager
/**
-
Updated implementation of ViewAttachmentManager with access to frameLayout
-
Don't forget to add to lifecycle observers otherwise View will not be rendered
*/
class ComposableViewAttachmentManager(
context: Context,
private val lifecycleOwner: LifecycleOwner,
private val viewModelStoreOwner: ViewModelStoreOwner,
private val savedStateRegistryOwner: SavedStateRegistryOwner,
private val ownerView: View // Used to post callbacks onto the UI thread.
): ViewAttachmentManager(context, ownerView), DefaultLifecycleObserver {
private val windowManager: WindowManager
private val windowLayoutParams: WindowManager.LayoutParams
private val frameLayout: FrameLayout
private val viewLayoutParams: ViewGroup.LayoutParamsinit {
windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
windowLayoutParams = createWindowLayoutParams()
frameLayout = FrameLayout(context)
viewLayoutParams = createViewLayoutParams()frameLayout.setViewTreeLifecycleOwner(lifecycleOwner) frameLayout.setViewTreeSavedStateRegistryOwner(savedStateRegistryOwner) frameLayout.setViewTreeViewModelStoreOwner(viewModelStoreOwner)
}
override fun onResume(owner: LifecycleOwner) {
onResume()
}override fun onPause(owner: LifecycleOwner) {
onPause()
}override fun onResume() {
// A ownerView can only be added to the WindowManager after the activity has finished resuming.
// Therefore, we must use post to ensure that the window is only added after resume is finished.
ownerView.post {
if (frameLayout.parent == null && ownerView.isAttachedToWindow) {
windowManager.addView(frameLayout, windowLayoutParams)
}
}
}override fun onPause() {
// The ownerView must be removed from the WindowManager before the activity is destroyed, or the
// window will be leaked. Therefore we add/remove the ownerView in resume/pause.
if (frameLayout.parent != null) {
windowManager.removeView(frameLayout)
}
}/**
- Add a ownerView as a child of the [FrameLayout] that is attached to the [ ].
- Used by [RenderViewToExternalTexture] to ensure that the ownerView is drawn with all
- appropriate lifecycle events being called correctly.
*/
override fun addView(view: View) {
if (view.parent === frameLayout) {
return
}
frameLayout.addView(view, viewLayoutParams)
}
/**
- Remove a ownerView from the [FrameLayout] that is attached to the [WindowManager].
- Used by [RenderViewToExternalTexture] to remove ownerView's that no longer need to be
- drawn.
*/
override fun removeView(view: View) {
if (view.parent !== frameLayout) {
return
}
frameLayout.removeView(view)
}
companion object {
private const val VIEW_RENDERABLE_WINDOW = "ViewRenderableWindow"
private fun createWindowLayoutParams(): WindowManager.LayoutParams {
val params = WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
or WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT
)
params.title = VIEW_RENDERABLE_WINDOW
return params
}private fun createViewLayoutParams(): ViewGroup.LayoutParams { return ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) }
}
}
`
from sceneview-android.
Related Issues (20)
- ARScene crashes on compose when disposing element HOT 1
- Projection matrix is not updated in augmented face mode HOT 9
- Exception: Calling method on destroyed Scene when Scene is shown and hidden in Compose HOT 1
- ViewNode for 2.1.0 HOT 3
- Crash on destroying the ArSceneView HOT 8
- Crash on closing SceneView with child node HOT 1
- ar-cloud-anchor sample + azure
- NullPointerException on screen rotation HOT 2
- Correct way to set background color/ using skybox causes black flash momentarily
- Animate Node transform/How to create Node Animations
- Can't add session features during ARCore initialization in ARSceneView HOT 2
- Scene does not work inside LazyColumn HOT 1
- Stop the animation at last frame of animation playback HOT 1
- Human Skin Scan
- Not able to update GLB model consistently in existing Compose ARSceneView
- Crash on disposing AR Scene in 2.1.0 HOT 2
- Node shaking issue
- Models not displaying right on device but they look ok on emulator with isOpaque = false
- Augmented faces
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sceneview-android.