Explorar el Código

ios: Added property for setting PiP initial position

master
Mihai Damian hace 6 años
padre
commit
477826089c
Se han modificado 1 ficheros con 24 adiciones y 3 borrados
  1. 24
    3
      ios/sdk/src/picture-in-picture/PiPViewCoordinator.swift

+ 24
- 3
ios/sdk/src/picture-in-picture/PiPViewCoordinator.swift Ver fichero

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
     /// The size ratio of the view when in PiP mode
49
     /// The size ratio of the view when in PiP mode
41
     public var pipSizeRatio: CGFloat = {
50
     public var pipSizeRatio: CGFloat = {
42
         let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
51
         let deviceIdiom = UIScreen.main.traitCollection.userInterfaceIdiom
205
         let adjustedBounds = bounds.inset(by: dragBoundInsets)
214
         let adjustedBounds = bounds.inset(by: dragBoundInsets)
206
         let size = CGSize(width: bounds.size.width * pipSizeRatio,
215
         let size = CGSize(width: bounds.size.width * pipSizeRatio,
207
                           height: bounds.size.height * pipSizeRatio)
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
     // MARK: - Animation helpers
234
     // MARK: - Animation helpers

Loading…
Cancelar
Guardar