Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
fix: PageView component size
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasaraujo committed Apr 28, 2021
1 parent 3a83bde commit 874c74e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ class CustomPageIndicatorTests: XCTestCase {
children: Array(repeating: page, count: 3),
pageIndicator: indicator
)
let view = BeagleView(component)
view.backgroundColor = .white

let screen = BeagleScreenViewController(viewModel: .init(
screenType: .declarative(component.toScreen()),
dependencies: dependencies
))

assertSnapshotImage(screen)
assertSnapshotImage(view)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ class PageViewTests: XCTestCase {

let pageView = PageView(children: [ComponentDummy()], pageIndicator: nil)
let view = pageView.toView(renderer: controller.renderer)
let page = (view as? PageViewUIComponent)?.pageViewController.viewControllers?.first
let componentView = view.subviews.compactMap({ $0 as? PageViewUIComponent }).first
let page = componentView?.pageViewController.viewControllers?.first

XCTAssertEqual(page?.navigationController, navigation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,42 @@ import UIKit
extension PageView {

public func toView(renderer: BeagleRenderer) -> UIView {
let pagesControllers = children?.map {
ComponentHostController($0, renderer: renderer)
let view = UIView()
let indicatorView = pageIndicator.ifSome {
renderer.render($0) as? PageIndicatorUIView & UIView
}

var indicatorView: PageIndicatorUIView?
if let indicator = pageIndicator {
indicatorView = renderer.render(indicator) as? PageIndicatorUIView
}

let view = PageViewUIComponent(
model: .init(pages: pagesControllers ?? []),
let pagesView = PageViewUIComponent(
model: .init(pages: (children ?? []).map {
ComponentHostController($0, renderer: renderer)
}),
indicatorView: indicatorView,
controller: renderer.controller
)

if let actions = onPageChange {
view.onPageChange = { [weak view] page in
guard let view = view else { return }
renderer.controller?.execute(actions: actions, with: "onPageChange", and: .int(page), origin: view)
pagesView.onPageChange = { [weak view] page in
guard let view = view else { return }
renderer.controller?.execute(actions: onPageChange, with: "onPageChange", and: .int(page), origin: view)
}
renderer.observe(currentPage, andUpdateManyIn: view) { [weak pagesView] page in
if let page = page {
pagesView?.swipeToPage(at: page)
}
}

renderer.observe(currentPage, andUpdateManyIn: view) { [weak view] page in
if let view = view, let page = page {
view.swipeToPage(at: page)
}
view.backgroundColor = .clear
renderer.dependencies.style(view).setup(Style(flex: Flex().flexDirection(.column)))

view.addSubview(pagesView)
renderer.dependencies.style(pagesView).setup(Style(flex: Flex(grow: 1)))

if let indicatorView = indicatorView {
view.addSubview(indicatorView)
let style = Style()
.size(Size().height(40))
.margin(EdgeValue().top(10))
.flex(Flex().shrink(0))
renderer.dependencies.style(indicatorView).setup(style)
}

view.style.setup(Style(flex: Flex(grow: 1.0)))

return view
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class PageViewUIComponent: UIView {
controller?.addChild(pageViewController)
addSubview(pageViewController.view)
pageViewController.didMove(toParent: controller)
pageViewController.view.anchorTo(superview: self)

if let firstPage = model.pages.first {
pageViewController.setViewControllers(
Expand All @@ -88,15 +89,10 @@ class PageViewUIComponent: UIView {
}
pageViewController.dataSource = self
pageViewController.delegate = self
pageViewController.view.style.setup(Style(flex: Flex().grow(1)))

if let indicator = indicatorView as? UIView {
indicator.style.setup(Style(size: Size().height(40), margin: EdgeValue().top(10)))
indicator.yoga.isEnabled = true
addSubview(indicator)
}

style.applyLayout()
}

override func sizeThatFits(_ size: CGSize) -> CGSize {
return size
}

// MARK: - Update
Expand Down
4 changes: 0 additions & 4 deletions iOS/Tests/AutomatedTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
639CA24124B51B40009FAC90 /* BeagleConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 639CA24024B51B40009FAC90 /* BeagleConfig.swift */; };
63ED0EFC24B785960086E433 /* Beagle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63ED0EF624B782EB0086E433 /* Beagle.framework */; };
63ED0EFD24B785960086E433 /* Beagle.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 63ED0EF624B782EB0086E433 /* Beagle.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
63ED0F0124B785A10086E433 /* YogaKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 63ED0EFA24B782EB0086E433 /* YogaKit.framework */; };
63ED0F0224B785A10086E433 /* YogaKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 63ED0EFA24B782EB0086E433 /* YogaKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
6B4F7E7B24C65A76003F461A /* ScreenRobot.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4F7E7A24C65A76003F461A /* ScreenRobot.swift */; };
6B4F7E7D24C65AFE003F461A /* ScreenElements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4F7E7C24C65AFE003F461A /* ScreenElements.swift */; };
6B4F7E8524C9C5F9003F461A /* ListViewSteps.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4F7E8424C9C5F9003F461A /* ListViewSteps.swift */; };
Expand Down Expand Up @@ -111,7 +109,6 @@
dstSubfolderSpec = 10;
files = (
63ED0EFD24B785960086E433 /* Beagle.framework in Embed Frameworks */,
63ED0F0224B785A10086E433 /* YogaKit.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -268,7 +265,6 @@
buildActionMask = 2147483647;
files = (
63ED0EFC24B785960086E433 /* Beagle.framework in Frameworks */,
63ED0F0124B785A10086E433 /* YogaKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 874c74e

Please sign in to comment.