Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
ASCollectionView
Commits
c4b2c7d8
Commit
c4b2c7d8
authored
5 years ago
by
Apptek Studios
Browse files
Options
Download
Email Patches
Plain Diff
Refine header caching
parent
ffddb7df
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
Sources/ASCollectionView/Cells/ASCollectionViewDecoration.swift
+1
-1
...s/ASCollectionView/Cells/ASCollectionViewDecoration.swift
Sources/ASCollectionView/Cells/ASCollectionViewSupplementaryView.swift
+0
-12
...lectionView/Cells/ASCollectionViewSupplementaryView.swift
Sources/ASCollectionView/Cells/ASTableViewSupplementaryView.swift
+5
-1
...ASCollectionView/Cells/ASTableViewSupplementaryView.swift
Sources/ASCollectionView/Implementation/ASCollectionView.swift
+2
-3
...es/ASCollectionView/Implementation/ASCollectionView.swift
Sources/ASCollectionView/Implementation/ASTableView.swift
+31
-22
Sources/ASCollectionView/Implementation/ASTableView.swift
with
39 additions
and
39 deletions
+39
-39
Sources/ASCollectionView/Cells/ASCollectionViewDecoration.swift
+
1
-
1
View file @
c4b2c7d8
...
...
@@ -17,7 +17,7 @@ class ASCollectionViewDecoration<Content: Decoration>: ASCollectionViewSupplemen
{
super
.
init
(
frame
:
frame
)
let
view
=
Content
()
setupFor
(
view
:
view
)
hostingController
=
ASHostingController
(
view
)
willAppear
(
in
:
nil
)
}
...
...
This diff is collapsed.
Click to expand it.
Sources/ASCollectionView/Cells/ASCollectionViewSupplementaryView.swift
+
0
-
12
View file @
c4b2c7d8
...
...
@@ -12,18 +12,6 @@ class ASCollectionViewSupplementaryView: UICollectionReusableView
var
selfSizingConfig
:
ASSelfSizingConfig
=
.
init
(
selfSizeHorizontally
:
true
,
selfSizeVertically
:
true
)
var
maxSizeForSelfSizing
:
ASOptionalSize
=
.
none
func
setupFor
<
Content
:
View
>
(
view
:
Content
)
{
if
let
hc
=
hostingController
as?
ASHostingController
<
Content
>
{
hc
.
setView
(
view
)
}
else
{
hostingController
=
ASHostingController
<
Content
>
(
view
)
}
}
func
setupForEmpty
()
{
hostingController
=
nil
...
...
This diff is collapsed.
Click to expand it.
Sources/ASCollectionView/Cells/ASTableViewSupplementaryView.swift
+
5
-
1
View file @
c4b2c7d8
...
...
@@ -7,7 +7,11 @@ import UIKit
@available
(
iOS
13.0
,
*
)
class
ASTableViewSupplementaryView
:
UITableViewHeaderFooterView
{
var
hostingController
:
ASHostingControllerProtocol
?
var
hostingController
:
ASHostingControllerProtocol
?
{
didSet
{
setNeedsLayout
()
}
}
var
sectionIDHash
:
Int
?
override
init
(
reuseIdentifier
:
String
?)
...
...
This diff is collapsed.
Click to expand it.
Sources/ASCollectionView/Implementation/ASCollectionView.swift
+
2
-
3
View file @
c4b2c7d8
...
...
@@ -326,9 +326,8 @@ public struct ASCollectionView<SectionID: Hashable>: UIViewControllerRepresentab
{
kind
in
cv
.
indexPathsForVisibleSupplementaryElements
(
ofKind
:
kind
)
.
forEach
{
guard
let
supplementaryView
=
parent
.
sections
[
safe
:
$0
.
section
]?
.
supplementary
(
ofKind
:
kind
)
else
{
return
}
(
cv
.
supplementaryView
(
forElementKind
:
kind
,
at
:
$0
)
as?
ASCollectionViewSupplementaryView
)?
.
setupFor
(
view
:
supplementaryView
)
guard
let
view
=
(
cv
.
supplementaryView
(
forElementKind
:
kind
,
at
:
$0
)
as?
ASCollectionViewSupplementaryView
)
else
{
return
}
view
.
hostingController
=
parent
.
sections
[
safe
:
$0
.
section
]?
.
dataSource
.
updateOrCreateHostController
(
forSupplementaryKind
:
kind
,
existingHC
:
view
.
hostingController
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Sources/ASCollectionView/Implementation/ASTableView.swift
+
31
-
22
View file @
c4b2c7d8
...
...
@@ -108,6 +108,8 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
private
var
hasDoneInitialSetup
=
false
private
var
hasSkippedFirstUpdate
=
false
private
var
visibleSupplementaries
:
[
ASSupplementaryCellID
<
SectionID
>
:
ASTableViewSupplementaryView
]
=
[:]
// MARK: Caching
...
...
@@ -254,23 +256,10 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
else
{
return
}
self
.
section
(
forItemID
:
itemID
)?
.
dataSource
.
update
(
hc
,
forItemID
:
itemID
)
}
tv
.
visibleHeaderViews
.
forEach
{
view
in
guard
let
view
=
view
as?
ASTableViewSupplementaryView
,
let
sectionIDHash
=
view
.
sectionIDHash
,
let
hc
=
view
.
hostingController
else
{
return
}
self
.
parent
.
sections
.
first
(
where
:
{
$0
.
id
.
hashValue
==
sectionIDHash
})?
.
dataSource
.
update
(
hc
,
forSupplementaryKind
:
UICollectionView
.
elementKindSectionHeader
)
}
tv
.
visibleFooterViews
.
forEach
{
view
in
guard
let
view
=
view
as?
ASTableViewSupplementaryView
,
let
sectionIDHash
=
view
.
sectionIDHash
,
let
hc
=
view
.
hostingController
else
{
return
}
self
.
parent
.
sections
.
first
(
where
:
{
$0
.
id
.
hashValue
==
sectionIDHash
})?
.
dataSource
.
update
(
hc
,
forSupplementaryKind
:
UICollectionView
.
elementKindSectionFooter
)
visibleSupplementaries
.
forEach
{
(
key
,
view
)
in
guard
let
section
=
self
.
parent
.
sections
.
first
(
where
:
{
$0
.
id
.
hashValue
==
key
.
sectionID
.
hashValue
})
else
{
return
}
view
.
hostingController
=
section
.
dataSource
.
updateOrCreateHostController
(
forSupplementaryKind
:
key
.
supplementaryKind
,
existingHC
:
view
.
hostingController
)
}
}
...
...
@@ -306,7 +295,7 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
var
lastContentSize
:
CGSize
=
.
zero
func
didUpdateContentSize
(
_
size
:
CGSize
)
{
guard
let
tv
=
tableViewController
?
.
tableView
,
tv
.
contentSize
!=
lastContentSize
else
{
return
}
guard
let
tv
=
tableViewController
?
.
tableView
,
tv
.
contentSize
!=
lastContentSize
,
tv
.
contentSize
.
height
!=
0
else
{
return
}
let
firstSize
=
lastContentSize
==
.
zero
lastContentSize
=
tv
.
contentSize
parent
.
contentSizeTracker
?
.
contentSize
=
size
...
...
@@ -357,22 +346,42 @@ public struct ASTableView<SectionID: Hashable>: UIViewControllerRepresentable, C
public
func
tableView
(
_
tableView
:
UITableView
,
willDisplayHeaderView
view
:
UIView
,
forSection
section
:
Int
)
{
tableViewController
.
map
{
(
view
as?
ASTableViewSupplementaryView
)?
.
willAppear
(
in
:
$0
)
}
guard
let
view
=
(
view
as?
ASTableViewSupplementaryView
)
else
{
return
}
if
let
section
=
parent
.
sections
[
safe
:
section
]
{
let
supplementaryID
=
ASSupplementaryCellID
(
sectionID
:
section
.
id
,
supplementaryKind
:
UICollectionView
.
elementKindSectionHeader
)
visibleSupplementaries
[
supplementaryID
]
=
view
}
tableViewController
.
map
{
view
.
willAppear
(
in
:
$0
)
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
didEndDisplayingHeaderView
view
:
UIView
,
forSection
section
:
Int
)
{
(
view
as?
ASTableViewSupplementaryView
)?
.
didDisappear
()
guard
let
view
=
(
view
as?
ASTableViewSupplementaryView
)
else
{
return
}
if
let
section
=
parent
.
sections
[
safe
:
section
]
{
let
supplementaryID
=
ASSupplementaryCellID
(
sectionID
:
section
.
id
,
supplementaryKind
:
UICollectionView
.
elementKindSectionHeader
)
visibleSupplementaries
.
removeValue
(
forKey
:
supplementaryID
)
}
view
.
didDisappear
()
}
public
func
tableView
(
_
tableView
:
UITableView
,
willDisplayFooterView
view
:
UIView
,
forSection
section
:
Int
)
{
tableViewController
.
map
{
(
view
as?
ASTableViewSupplementaryView
)?
.
willAppear
(
in
:
$0
)
}
guard
let
view
=
(
view
as?
ASTableViewSupplementaryView
)
else
{
return
}
if
let
section
=
parent
.
sections
[
safe
:
section
]
{
let
supplementaryID
=
ASSupplementaryCellID
(
sectionID
:
section
.
id
,
supplementaryKind
:
UICollectionView
.
elementKindSectionFooter
)
visibleSupplementaries
[
supplementaryID
]
=
view
}
tableViewController
.
map
{
view
.
willAppear
(
in
:
$0
)
}
}
public
func
tableView
(
_
tableView
:
UITableView
,
didEndDisplayingFooterView
view
:
UIView
,
forSection
section
:
Int
)
{
(
view
as?
ASTableViewSupplementaryView
)?
.
didDisappear
()
guard
let
view
=
(
view
as?
ASTableViewSupplementaryView
)
else
{
return
}
if
let
section
=
parent
.
sections
[
safe
:
section
]
{
let
supplementaryID
=
ASSupplementaryCellID
(
sectionID
:
section
.
id
,
supplementaryKind
:
UICollectionView
.
elementKindSectionFooter
)
visibleSupplementaries
.
removeValue
(
forKey
:
supplementaryID
)
}
view
.
didDisappear
()
}
public
func
tableView
(
_
tableView
:
UITableView
,
prefetchRowsAt
indexPaths
:
[
IndexPath
])
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets