Skip to content

Commit

Permalink
Merge branch 'widgets_support'
Browse files Browse the repository at this point in the history
  • Loading branch information
denis-obukhov committed Dec 8, 2020
2 parents 05dd40a + 9d14096 commit 54d81af
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- ExyteGrid (1.1.0)
- ExyteGrid (1.1.1.beta)

DEPENDENCIES:
- ExyteGrid (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
ExyteGrid: 4adc3922b68a8fbcdf6c3728e5bd140be1e38440
ExyteGrid: feea67822226ffc637c348e952627461d5bb076f

PODFILE CHECKSUM: 76084cf935f120b28a0e2dcc60936504183d3608

Expand Down
2 changes: 1 addition & 1 deletion ExyteGrid.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'ExyteGrid'
s.version = '1.1.0'
s.version = '1.1.1.beta'
s.summary = 'The most powerful Grid container missed in SwiftUI'

s.homepage = 'https://github.com/exyte/Grid.git'
Expand Down
6 changes: 6 additions & 0 deletions Grid.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
369E503625331A18007CEADA /* ArrangingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 361723B52475230A00866539 /* ArrangingTest.swift */; };
369E503725331A18007CEADA /* PositionColumnScrollTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 361723B42475230A00866539 /* PositionColumnScrollTest.swift */; };
36E46504253319C90084C6EF /* GridMac.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 363AD4732530455F00C27F2F /* GridMac.framework */; };
36E9CF48257F3EC500AE5E65 /* View+If.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E9CF47257F3EC500AE5E65 /* View+If.swift */; };
36E9CF49257F3EC500AE5E65 /* View+If.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E9CF47257F3EC500AE5E65 /* View+If.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -160,6 +162,7 @@
365DFA352523543C0019BB80 /* Grid+Init.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Grid+Init.swift"; sourceTree = "<group>"; };
36E464FF253319C90084C6EF /* GridMacTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = GridMacTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
36E46503253319C90084C6EF /* MacTestsInfo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = MacTestsInfo.plist; sourceTree = "<group>"; };
36E9CF47257F3EC500AE5E65 /* View+If.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+If.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -274,6 +277,7 @@
3633AB9124E678410033A172 /* CGRect+Hashable.swift */,
3633AB9024E678410033A172 /* CGSize+Hashable.swift */,
361723682475221000866539 /* LayoutArrangement+description.swift */,
36E9CF47257F3EC500AE5E65 /* View+If.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -553,6 +557,7 @@
3633AB8E24E678290033A172 /* Cache.swift in Sources */,
361723A02475221000866539 /* PositionedItem.swift in Sources */,
361723802475221000866539 /* LayoutArranging.swift in Sources */,
36E9CF48257F3EC500AE5E65 /* View+If.swift in Sources */,
365DFA372523543C0019BB80 /* GridGroup+Inits_Data.swift in Sources */,
3617238B2475221000866539 /* View+Environment.swift in Sources */,
361723962475221000866539 /* GridStart.swift in Sources */,
Expand Down Expand Up @@ -632,6 +637,7 @@
363AD497253045A200C27F2F /* GridGroup.swift in Sources */,
363AD4AC253045A200C27F2F /* CGRect+Hashable.swift in Sources */,
363AD4A1253045A200C27F2F /* GridContentViewsProtocols.swift in Sources */,
36E9CF49257F3EC500AE5E65 /* View+If.swift in Sources */,
363AD4A4253045A200C27F2F /* LayoutArrangement.swift in Sources */,
363AD49B253045A200C27F2F /* GridTrack.swift in Sources */,
);
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ func headerSegment(flag: Bool) -> some View {

## Release notes:

##### [v1.1.1.beta](https://github.com/exyte/Grid/releases/tag/1.1.1.beta):
- adds WidgetKit support by conditionally rendering ScrollView

##### [v1.1.0](https://github.com/exyte/Grid/releases/tag/1.1.0):
- adds MacOS support

Expand Down
20 changes: 20 additions & 0 deletions Sources/Extensions/View+If.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// View+If.swift
// Grid
//
// Created by Denis Obukhov on 08.12.2020.
// Copyright © 2020 Exyte. All rights reserved.
//

import SwiftUI

extension View {
@ViewBuilder
func `if`<Content: View>(_ conditional: Bool, content: (Self) -> Content) -> some View {
if conditional {
content(self)
} else {
self
}
}
}
53 changes: 27 additions & 26 deletions Sources/View/Grid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,34 @@ public struct Grid: View, LayoutArranging, LayoutPositioning {

public var body: some View {
return GeometryReader { mainGeometry in
ScrollView(self.scrollAxis) {
ZStack(alignment: .topLeading) {
ForEach(self.items) { item in
item.view
.padding(spacing: self.spacing)
.background(self.positionsPreferencesSetter(item: item,
boundingSize: mainGeometry.size))
.transformPreference(GridPreferenceKey.self) { preference in
preference.itemsInfo = preference.itemsInfo.mergedToSingleValue
}
.frame(flow: self.flow,
size: self.positions[item]?.bounds.size,
contentMode: self.contentMode)
.alignmentGuide(.leading, computeValue: { _ in self.leadingGuide(item: item) })
.alignmentGuide(.top, computeValue: { _ in self.topGuide(item: item) })
.backgroundPreferenceValue(GridBackgroundPreferenceKey.self) { preference in
self.cellPreferenceView(item: item, preference: preference)
}
.overlayPreferenceValue(GridOverlayPreferenceKey.self) { preference in
self.cellPreferenceView(item: item, preference: preference)
}
}
ZStack(alignment: .topLeading) {
ForEach(self.items) { item in
item.view
.padding(spacing: self.spacing)
.background(self.positionsPreferencesSetter(item: item,
boundingSize: mainGeometry.size))
.transformPreference(GridPreferenceKey.self) { preference in
preference.itemsInfo = preference.itemsInfo.mergedToSingleValue
}
.frame(flow: self.flow,
size: self.positions[item]?.bounds.size,
contentMode: self.contentMode)
.alignmentGuide(.leading, computeValue: { _ in self.leadingGuide(item: item) })
.alignmentGuide(.top, computeValue: { _ in self.topGuide(item: item) })
.backgroundPreferenceValue(GridBackgroundPreferenceKey.self) { preference in
self.cellPreferenceView(item: item, preference: preference)
}
.overlayPreferenceValue(GridOverlayPreferenceKey.self) { preference in
self.cellPreferenceView(item: item, preference: preference)
}
}
.animation(self.gridAnimation)
.frame(flow: self.flow,
size: mainGeometry.size,
contentMode: self.contentMode)
}
.animation(self.gridAnimation)
.frame(flow: self.flow,
size: mainGeometry.size,
contentMode: self.contentMode)
.if(contentMode == .scroll) { content in
ScrollView(self.scrollAxis) { content }
}
.onPreferenceChange(GridPreferenceKey.self) { preference in
self.calculateLayout(preference: preference,
Expand Down

0 comments on commit 54d81af

Please sign in to comment.