davidliu
Committed by GitHub

Compose visibility fixes (#85)

* Fix sending up updates when not automanaging video

* Fix compose visibility
@@ -40,7 +40,7 @@ class RemoteTrackPublication( @@ -40,7 +40,7 @@ class RemoteTrackPublication(
40 } 40 }
41 } 41 }
42 42
43 - if (value is RemoteVideoTrack) { 43 + if (value is RemoteVideoTrack && value.autoManageVideo) {
44 handleVideoDimensionsChanged(value.lastDimensions) 44 handleVideoDimensionsChanged(value.lastDimensions)
45 handleVisibilityChanged(value.lastVisibility) 45 handleVisibilityChanged(value.lastVisibility)
46 } 46 }
@@ -33,33 +33,41 @@ abstract class VideoSinkVisibility : Observable() { @@ -33,33 +33,41 @@ abstract class VideoSinkVisibility : Observable() {
33 } 33 }
34 34
35 class ComposeVisibility : VideoSinkVisibility() { 35 class ComposeVisibility : VideoSinkVisibility() {
36 - private var lastCoordinates: LayoutCoordinates? = null 36 + private var coordinates: LayoutCoordinates? = null
37 37
  38 + private var lastVisible = isVisible()
  39 + private var lastSize = size()
38 override fun isVisible(): Boolean { 40 override fun isVisible(): Boolean {
39 - return (lastCoordinates?.isAttached == true && lastCoordinates?.size?.width != 0 && lastCoordinates?.size?.height != 0) 41 + return (coordinates?.isAttached == true &&
  42 + coordinates?.size?.width != 0 &&
  43 + coordinates?.size?.height != 0)
40 } 44 }
41 45
42 override fun size(): Track.Dimensions { 46 override fun size(): Track.Dimensions {
43 - val width = lastCoordinates?.size?.width ?: 0  
44 - val height = lastCoordinates?.size?.height ?: 0 47 + val width = coordinates?.size?.width ?: 0
  48 + val height = coordinates?.size?.height ?: 0
45 return Track.Dimensions(width, height) 49 return Track.Dimensions(width, height)
46 } 50 }
47 51
  52 + // Note, LayoutCoordinates are mutable and may be reused.
48 fun onGloballyPositioned(layoutCoordinates: LayoutCoordinates) { 53 fun onGloballyPositioned(layoutCoordinates: LayoutCoordinates) {
49 - val lastVisible = isVisible()  
50 - val lastSize = size()  
51 - lastCoordinates = layoutCoordinates 54 + coordinates = layoutCoordinates
  55 + val visible = isVisible()
  56 + val size = size()
52 57
53 - if (lastVisible != isVisible() || lastSize != size()) { 58 + if (lastVisible != visible || lastSize != size) {
54 notifyChanged() 59 notifyChanged()
55 } 60 }
  61 +
  62 + lastVisible = visible
  63 + lastSize = size
56 } 64 }
57 65
58 fun onDispose() { 66 fun onDispose() {
59 - if (lastCoordinates == null) { 67 + if (coordinates == null) {
60 return 68 return
61 } 69 }
62 - lastCoordinates = null 70 + coordinates = null
63 notifyChanged() 71 notifyChanged()
64 } 72 }
65 } 73 }