Sfoglia il codice sorgente

ios: Added property for setting PiP initial position

master
Mihai Damian 6 anni fa
parent
commit
477826089c
1 ha cambiato i file con 24 aggiunte e 3 eliminazioni
  1. 24
    3
      ios/sdk/src/picture-in-picture/PiPViewCoordinator.swift

+ 24
- 3
ios/sdk/src/picture-in-picture/PiPViewCoordinator.swift Vedi File

@@ -37,6 +37,15 @@ public class PiPViewCoordinator {
37 37
         }
38 38
     }
39 39
 
40
+    public enum Position {
41
+        case lowerRightCorner
42
+        case upperRightCorner
43
+        case lowerLeftCorner
44
+        case upperLeftCorner
45
+    }
46
+    
47
+    public var initialPositionInSuperview = Position.lowerRightCorner
48
+    
40 49
     /// The size ratio of the view when in PiP mode
41 50
     public var pipSizeRatio: CGFloat = {
42 51
         let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
@@ -205,9 +214,21 @@ public class PiPViewCoordinator {
205 214
         let adjustedBounds = bounds.inset(by: dragBoundInsets)
206 215
         let size = CGSize(width: bounds.size.width * pipSizeRatio,
207 216
                           height: bounds.size.height * pipSizeRatio)
208
-        let x: CGFloat = adjustedBounds.maxX - size.width
209
-        let y: CGFloat = adjustedBounds.maxY - size.height
210
-        return CGRect(x: x, y: y, width: size.width, height: size.height)
217
+        let origin = initialPositionFor(pipSize: size, bounds: adjustedBounds)
218
+        return CGRect(x: origin.x, y: origin.y, width: size.width, height: size.height)
219
+    }
220
+    
221
+    private func initialPositionFor(pipSize size: CGSize, bounds: CGRect) -> CGPoint {
222
+        switch initialPositionInSuperview {
223
+        case .lowerLeftCorner:
224
+            return CGPoint(x: bounds.minX, y: bounds.maxY - size.height)
225
+        case .lowerRightCorner:
226
+            return CGPoint(x: bounds.maxX - size.width, y: bounds.maxY - size.height)
227
+        case .upperLeftCorner:
228
+            return CGPoint(x: bounds.minX, y: bounds.minY)
229
+        case .upperRightCorner:
230
+            return CGPoint(x: bounds.maxX - size.width, y: bounds.minY)
231
+        }
211 232
     }
212 233
 
213 234
     // MARK: - Animation helpers

Loading…
Annulla
Salva