•  


GitHub - spacenation/swiftui-grid: :rocket: SwiftUI Grid layout with custom styles
Skip to content
This repository has been archived by the owner on Dec 27, 2020. It is now read-only.

?? SwiftUI Grid layout with custom styles

License

Notifications You must be signed in to change notification settings

spacenation/swiftui-grid

Folders and files

Name Name
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

SwiftUI Grid

SwiftUI Grid view layout with custom styles.

Features

  • ZStack based layout
  • Vertical and horizontal scrolling
  • Supports all apple platforms
  • Custom styles (ModularGridStyle, StaggeredGridStyle)
  • SwiftUI code patterns (StyleStructs, EnvironmentValues, ViewBuilder)
  • Active development for production apps

Open GridDemo.xcodeproj for more examples for iOS, macOS, watchOS and tvOS

Styles

ModularGridStyle (Default)

ScrollView
 {

    Grid
(
colors
)
 {

        Rectangle
(
)

            .
foregroundColor
(
$0
)

    }

}

.
gridStyle
(

    ModularGridStyle
(
columns
:
 .
min
(
100
)
,
 rows
:
 .
fixed
(
100
)
)

)

StaggeredGridStyle

ScrollView
 {

    Grid
(
1
...
69
,
 id
:
 \
.
self
)
 {
 index 
in

        Image
(
"
\(
index
)
"
)

            .
resizable
(
)

            .
scaledToFit
(
)

    }

}

.
gridStyle
(

    StaggeredGridStyle
(
.
horizontal
,
 tracks
:
 8
,
 spacing
:
 4
)

)

Tracks

Tracks setting allows you to customize grid behaviour to your specific use-case. Both Modular and Staggered grid use tracks value to calculate layout. In Modular layout both columns and rows are tracks.

public
 enum
 Tracks
:
 Hashable
 {

    case
 count
(
Int
)

    case
 fixed
(
CGFloat
)

    case
 min
(
CGFloat
)

}

Count

Grid is split into equal fractions of size provided by a parent view.

ModularGridStyle
(
columns
:
 3
,
 rows
:
 3
)

StaggeredGridStyle
(
tracks
:
 8
)

Fixed

Item size is fixed to a specific width or height.

ModularGridStyle
(
columns
:
 .
fixed
(
100
)
,
 rows
:
 .
fixed
(
100
)
)

StaggeredGridStyle
(
tracks
:
 .
fixed
(
100
)
)

Min

Autolayout respecting a min item width or height.

ModularGridStyle
(
columns
:
 .
min
(
100
)
,
 rows
:
 .
fixed
(
100
)
)

StaggeredGridStyle
(
tracks
:
 .
min
(
100
)
)

Preferences

Get item size and position with preferences

struct
 CardsView
:
 View
 {

    @
State
 var
 selection
:
 Int
 =
 0

    
    var
 body
:
 some
 View
 {

        ScrollView
 {

            Grid
(
0
..<
100
)
 {
 number 
in

                Card
(
title
:
 "
\(
number
)
"
)

                    .
onTapGesture
 {

                        self
.
selection 
=
 number
                    
}

            }

            .
padding
(
)

            .
overlayPreferenceValue
(
GridItemBoundsPreferencesKey
.
self
)
 {
 preferences 
in

                RoundedRectangle
(
cornerRadius
:
 16
)

                    .
strokeBorder
(
lineWidth
:
 4
)

                    .
foregroundColor
(
.
white
)

                    .
frame
(

                        width
:
 preferences
[
self
.
selection
]
.
width
,

                        height
:
 preferences
[
self
.
selection
]
.
height
                    
)

                    .
position
(

                        x
:
 preferences
[
self
.
selection
]
.
midX
,

                        y
:
 preferences
[
self
.
selection
]
.
midY
                    
)

                    .
animation
(
.
linear
)

            }

        }

    }

}

SDKs

  • iOS 13.1+
  • Mac Catalyst 13.1+
  • macOS 10.15+
  • watchOS 6+
  • Xcode 11.0+

Roadmap

  • Items span
  • 'CSS Grid'-like features

Code Contributions

Feel free to contribute via fork/pull request to master branch. If you want to request a feature or report a bug please start a new issue.

Coffee Contributions

If you find this project useful please consider becoming my GitHub sponsor.

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본