From e3a36ca9303915eb0673586ac38af6a58904c7fa Mon Sep 17 00:00:00 2001 From: Daniel Tes Date: Fri, 16 Dec 2022 16:26:15 -0300 Subject: [PATCH] fix: useParentScroll related bug (#51) * fix: useParentScroll related bug Signed-off-by: Daniel Tes Carrasque * testCodableListView changes Signed-off-by: Daniel Tes Carrasque Signed-off-by: Daniel Tes Carrasque --- .../ListViewTests/testCodableListViewWithTemplate.1.json | 3 ++- .../Components/Widget/GridView/GridView+Extensions.swift | 3 ++- .../Beagle/Sources/Components/Widget/GridView/GridView.swift | 2 ++ .../Components/Widget/ListView/ListView+Extensions.swift | 3 ++- .../Beagle/Sources/Components/Widget/ListView/ListView.swift | 4 ++++ .../Components/Widget/ListView/ListViewUIComponent.swift | 5 +++++ 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Sources/Beagle/BeagleTests/Components/ServerDrivenComponent/ListView/__Snapshots__/ListViewTests/testCodableListViewWithTemplate.1.json b/Sources/Beagle/BeagleTests/Components/ServerDrivenComponent/ListView/__Snapshots__/ListViewTests/testCodableListViewWithTemplate.1.json index 027c6e2..82eb9d8 100644 --- a/Sources/Beagle/BeagleTests/Components/ServerDrivenComponent/ListView/__Snapshots__/ListViewTests/testCodableListViewWithTemplate.1.json +++ b/Sources/Beagle/BeagleTests/Components/ServerDrivenComponent/ListView/__Snapshots__/ListViewTests/testCodableListViewWithTemplate.1.json @@ -29,5 +29,6 @@ } } } - ] + ], + "useParentScroll" : true } \ No newline at end of file diff --git a/Sources/Beagle/Sources/Components/Widget/GridView/GridView+Extensions.swift b/Sources/Beagle/Sources/Components/Widget/GridView/GridView+Extensions.swift index 6d19cbf..b5b27fb 100644 --- a/Sources/Beagle/Sources/Components/Widget/GridView/GridView+Extensions.swift +++ b/Sources/Beagle/Sources/Components/Widget/GridView/GridView+Extensions.swift @@ -31,7 +31,8 @@ extension GridView { onScrollEnd: onScrollEnd, scrollEndThreshold: CGFloat(scrollEndThreshold ?? 100), isScrollIndicatorVisible: isScrollIndicatorVisible ?? false, - dataSourceExpression: dataSource + dataSourceExpression: dataSource, + useParentScroll: useParentScroll ), renderer: renderer ) diff --git a/Sources/Beagle/Sources/Components/Widget/GridView/GridView.swift b/Sources/Beagle/Sources/Components/Widget/GridView/GridView.swift index ddc2153..32bc6ff 100644 --- a/Sources/Beagle/Sources/Components/Widget/GridView/GridView.swift +++ b/Sources/Beagle/Sources/Components/Widget/GridView/GridView.swift @@ -58,6 +58,8 @@ public struct GridView: Widget, HasContext, InitiableComponent { /// This attribute enables or disables the scroll indicator. public var isScrollIndicatorVisible: Bool? + + public var useParentScroll: Bool? public var id: String? public var style: Style? diff --git a/Sources/Beagle/Sources/Components/Widget/ListView/ListView+Extensions.swift b/Sources/Beagle/Sources/Components/Widget/ListView/ListView+Extensions.swift index 5e1be78..14596f3 100644 --- a/Sources/Beagle/Sources/Components/Widget/ListView/ListView+Extensions.swift +++ b/Sources/Beagle/Sources/Components/Widget/ListView/ListView+Extensions.swift @@ -29,7 +29,8 @@ extension ListView { onScrollEnd: onScrollEnd, scrollEndThreshold: CGFloat(scrollEndThreshold ?? 100), isScrollIndicatorVisible: isScrollIndicatorVisible ?? false, - dataSourceExpression: dataSource + dataSourceExpression: dataSource, + useParentScroll: useParentScroll ), renderer: renderer ) diff --git a/Sources/Beagle/Sources/Components/Widget/ListView/ListView.swift b/Sources/Beagle/Sources/Components/Widget/ListView/ListView.swift index 1531543..19981ce 100644 --- a/Sources/Beagle/Sources/Components/Widget/ListView/ListView.swift +++ b/Sources/Beagle/Sources/Components/Widget/ListView/ListView.swift @@ -55,6 +55,8 @@ public struct ListView: Widget, HasContext, InitiableComponent { /// This attribute enables or disables the scroll indicator. public var isScrollIndicatorVisible: Bool? + + public var useParentScroll: Bool? public var id: String? public var style: Style? @@ -88,6 +90,7 @@ extension ListView { case id case style case accessibility + case useParentScroll } public init(from decoder: Decoder) throws { @@ -106,6 +109,7 @@ extension ListView { id = try container.decodeIfPresent(String.self, forKey: .id) style = try container.decodeIfPresent(Style.self, forKey: .style) ?? Style() accessibility = try container.decodeIfPresent(Accessibility.self, forKey: .accessibility) + useParentScroll = try container.decodeIfPresent(Bool.self, forKey: .useParentScroll) self.templates = try container.decodeIfPresent([Template].self, forKey: .templates) ?? [] self.dataSource = try container.decode(Expression<[DynamicObject]>.self, forKey: .dataSource) diff --git a/Sources/Beagle/Sources/Components/Widget/ListView/ListViewUIComponent.swift b/Sources/Beagle/Sources/Components/Widget/ListView/ListViewUIComponent.swift index e4a167c..ecab556 100644 --- a/Sources/Beagle/Sources/Components/Widget/ListView/ListViewUIComponent.swift +++ b/Sources/Beagle/Sources/Components/Widget/ListView/ListViewUIComponent.swift @@ -107,6 +107,10 @@ final class ListViewUIComponent: UIView { collection.delegate = self collection.showsHorizontalScrollIndicator = model.isScrollIndicatorVisible collection.showsVerticalScrollIndicator = model.isScrollIndicatorVisible + + if model.useParentScroll == true { + collection.isScrollEnabled = false + } let parentController = listController.renderer.controller parentController?.addChild(listController) @@ -244,6 +248,7 @@ extension ListViewUIComponent { var scrollEndThreshold: CGFloat var isScrollIndicatorVisible: Bool var dataSourceExpression: Expression<[DynamicObject]> + var useParentScroll: Bool? } }