|
|
|
|
@ -12,22 +12,19 @@ class ViewController: UIViewController {
|
|
|
|
|
let scrollView = UIScrollView()
|
|
|
|
|
let stackView = UIStackView()
|
|
|
|
|
stackView.axis = .vertical
|
|
|
|
|
stackView.spacing = 12 // Spacing between the "cards"
|
|
|
|
|
stackView.spacing = 12
|
|
|
|
|
|
|
|
|
|
let engine1 = FlutterEngine(name: "one")
|
|
|
|
|
engine1.run()
|
|
|
|
|
let engine = FlutterEngine()
|
|
|
|
|
engine.run()
|
|
|
|
|
|
|
|
|
|
for index in 1...50 {
|
|
|
|
|
if index == 10 {
|
|
|
|
|
// This is our Flutter view
|
|
|
|
|
let flutterViewController = FlutterViewController(engine: engine1, nibName: nil, bundle: nil)
|
|
|
|
|
if index == 1 {
|
|
|
|
|
let flutterViewController = FlutterViewController(engine: engine, nibName: nil, bundle: nil)
|
|
|
|
|
flutterViewController.isAutoResizable = true
|
|
|
|
|
addChild(flutterViewController)
|
|
|
|
|
|
|
|
|
|
// The Flutter view's background should be clear to see the card behind it
|
|
|
|
|
|
|
|
|
|
flutterViewController.view.backgroundColor = .clear
|
|
|
|
|
|
|
|
|
|
// Wrap the Flutter view in a styled container "card"
|
|
|
|
|
let cardView = UIView()
|
|
|
|
|
cardView.backgroundColor = .systemBackground
|
|
|
|
|
cardView.layer.cornerRadius = 12
|
|
|
|
|
@ -48,7 +45,7 @@ class ViewController: UIViewController {
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
let label = UILabel()
|
|
|
|
|
label.text = "It's me, iOS \(index)"
|
|
|
|
|
label.text = "iOS Label \(index)"
|
|
|
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
|
|
let cardView = UIView()
|
|
|
|
|
@ -67,14 +64,12 @@ class ViewController: UIViewController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// --- Auto Layout Setup ---
|
|
|
|
|
scrollView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
|
|
|
|
|
|
view.addSubview(scrollView)
|
|
|
|
|
scrollView.addSubview(stackView)
|
|
|
|
|
|
|
|
|
|
// Set constraints for the scroll view to fill the main view
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
|
scrollView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
|
|
|
|
|
scrollView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
|
|
|
|
|
@ -82,11 +77,9 @@ class ViewController: UIViewController {
|
|
|
|
|
scrollView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
// Set constraints for the stack view within the scroll view
|
|
|
|
|
NSLayoutConstraint.activate([
|
|
|
|
|
stackView.topAnchor.constraint(equalTo: scrollView.contentLayoutGuide.topAnchor, constant: 20),
|
|
|
|
|
stackView.bottomAnchor.constraint(equalTo: scrollView.contentLayoutGuide.bottomAnchor, constant: -20),
|
|
|
|
|
// Inset the stack view horizontally for the grouped look
|
|
|
|
|
stackView.leadingAnchor.constraint(equalTo: scrollView.frameLayoutGuide.leadingAnchor, constant: 20),
|
|
|
|
|
stackView.trailingAnchor.constraint(equalTo: scrollView.frameLayoutGuide.trailingAnchor, constant: -20)
|
|
|
|
|
])
|
|
|
|
|
|