Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
xx messenger iOS
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile
iOS
xx messenger iOS
Commits
09664e54
Commit
09664e54
authored
Jul 23, 2022
by
Bruno Muniz
Browse files
Options
Downloads
Patches
Plain Diff
Working on refactoring group creation
parent
f13e0ba8
No related branches found
No related tags found
1 merge request
!58
Migrating lists to compositional layout
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/ContactListFeature/Controllers/CreateGroupController.swift
+31
-29
31 additions, 29 deletions
...ontactListFeature/Controllers/CreateGroupController.swift
Sources/ContactListFeature/Views/CreateGroupView.swift
+18
-13
18 additions, 13 deletions
Sources/ContactListFeature/Views/CreateGroupView.swift
with
49 additions
and
42 deletions
Sources/ContactListFeature/Controllers/CreateGroupController.swift
+
31
−
29
View file @
09664e54
...
@@ -15,12 +15,12 @@ public final class CreateGroupController: UIViewController {
...
@@ -15,12 +15,12 @@ public final class CreateGroupController: UIViewController {
lazy
private
var
screenView
=
CreateGroupView
()
lazy
private
var
screenView
=
CreateGroupView
()
private
var
selectedElements
=
[
Contact
]()
{
private
var
selectedElements
=
[
Contact
]()
{
didSet
{
screenView
.
table
View
.
reloadData
()
}
didSet
{
screenView
.
bottomCollection
View
.
reloadData
()
}
}
}
private
let
viewModel
=
CreateGroupViewModel
()
private
let
viewModel
=
CreateGroupViewModel
()
private
var
cancellables
=
Set
<
AnyCancellable
>
()
private
var
cancellables
=
Set
<
AnyCancellable
>
()
private
var
t
able
DataSource
:
UI
Table
ViewDiffableDataSource
<
SectionId
,
Contact
>!
private
var
t
opCollection
DataSource
:
UI
Collection
ViewDiffableDataSource
<
SectionId
,
Contact
>!
private
var
c
ollectionDataSource
:
UICollectionViewDiffableDataSource
<
SectionId
,
Contact
>!
private
var
bottomC
ollectionDataSource
:
UICollectionViewDiffableDataSource
<
SectionId
,
Contact
>!
private
var
count
=
0
{
private
var
count
=
0
{
didSet
{
didSet
{
...
@@ -43,7 +43,7 @@ public final class CreateGroupController: UIViewController {
...
@@ -43,7 +43,7 @@ public final class CreateGroupController: UIViewController {
public
override
func
viewDidLoad
()
{
public
override
func
viewDidLoad
()
{
super
.
viewDidLoad
()
super
.
viewDidLoad
()
setupNavigationBar
()
setupNavigationBar
()
setup
TableAnd
Collection
()
setupCollection
Views
()
setupBindings
()
setupBindings
()
}
}
...
@@ -64,13 +64,12 @@ public final class CreateGroupController: UIViewController {
...
@@ -64,13 +64,12 @@ public final class CreateGroupController: UIViewController {
navigationItem
.
rightBarButtonItem
=
UIBarButtonItem
(
customView
:
createButton
)
navigationItem
.
rightBarButtonItem
=
UIBarButtonItem
(
customView
:
createButton
)
}
}
private
func
setupTableAndCollection
()
{
private
func
setupCollectionViews
()
{
screenView
.
tableView
.
rowHeight
=
64.0
screenView
.
bottomCollectionView
.
register
(
AvatarCell
.
self
)
screenView
.
tableView
.
register
(
AvatarCell
.
self
)
screenView
.
topCollectionView
.
register
(
CreateGroupCollectionCell
.
self
)
screenView
.
collectionView
.
register
(
CreateGroupCollectionCell
.
self
)
c
ollectionDataSource
=
UICollectionViewDiffableDataSource
<
SectionId
,
Contact
>
(
topC
ollectionDataSource
=
UICollectionViewDiffableDataSource
<
SectionId
,
Contact
>
(
collectionView
:
screenView
.
c
ollectionView
collectionView
:
screenView
.
topC
ollectionView
)
{
[
weak
viewModel
]
collectionView
,
indexPath
,
contact
in
)
{
[
weak
viewModel
]
collectionView
,
indexPath
,
contact
in
let
cell
:
CreateGroupCollectionCell
=
collectionView
.
dequeueReusableCell
(
forIndexPath
:
indexPath
)
let
cell
:
CreateGroupCollectionCell
=
collectionView
.
dequeueReusableCell
(
forIndexPath
:
indexPath
)
...
@@ -81,26 +80,28 @@ public final class CreateGroupController: UIViewController {
...
@@ -81,26 +80,28 @@ public final class CreateGroupController: UIViewController {
return
cell
return
cell
}
}
tableDataSource
=
DiffEdit
ableDataSource
<
SectionId
,
Contact
>
(
bottomCollectionDataSource
=
UICollectionViewDiff
ableDataSource
<
SectionId
,
Contact
>
(
table
View
:
screenView
.
table
View
collection
View
:
screenView
.
bottomCollection
View
)
{
[
weak
self
]
table
View
,
indexPath
,
contact
in
)
{
[
weak
self
]
collection
View
,
indexPath
,
contact
in
let
cell
=
table
View
.
dequeueReusableCell
(
forIndexPath
:
indexPath
,
ofType
:
AvatarCell
.
self
)
let
cell
:
AvatarCell
=
collection
View
.
dequeueReusableCell
(
forIndexPath
:
indexPath
)
let
title
=
(
contact
.
nickname
??
contact
.
username
)
??
""
let
title
=
(
contact
.
nickname
??
contact
.
username
)
??
""
cell
.
set
(
image
:
contact
.
photo
,
h1Text
:
title
)
cell
.
set
(
image
:
contact
.
photo
,
h1Text
:
title
)
if
let
selectedElements
=
self
?
.
selectedElements
,
selectedElements
.
contains
(
contact
)
{
if
let
selectedElements
=
self
?
.
selectedElements
,
selectedElements
.
contains
(
contact
)
{
table
View
.
select
Row
(
at
:
indexPath
,
animated
:
true
,
scrollPosition
:
.
none
)
collection
View
.
select
Item
(
at
:
indexPath
,
animated
:
true
,
scrollPosition
:
[]
)
}
else
{
}
else
{
table
View
.
deselect
Row
(
at
:
indexPath
,
animated
:
true
)
collection
View
.
deselect
Item
(
at
:
indexPath
,
animated
:
true
)
}
}
return
cell
return
cell
}
}
screenView
.
tableView
.
delegate
=
self
screenView
.
bottomCollectionView
.
delegate
=
self
screenView
.
tableView
.
dataSource
=
tableDataSource
screenView
.
topCollectionView
.
dataSource
=
topCollectionDataSource
screenView
.
collectionView
.
dataSource
=
collectionDataSource
screenView
.
bottomCollectionView
.
tintColor
=
Asset
.
brandPrimary
.
color
screenView
.
bottomCollectionView
.
dataSource
=
bottomCollectionDataSource
screenView
.
bottomCollectionView
.
allowsMultipleSelectionDuringEditing
=
true
}
}
private
func
setupBindings
()
{
private
func
setupBindings
()
{
...
@@ -114,7 +115,7 @@ public final class CreateGroupController: UIViewController {
...
@@ -114,7 +115,7 @@ public final class CreateGroupController: UIViewController {
selected
selected
.
receive
(
on
:
DispatchQueue
.
main
)
.
receive
(
on
:
DispatchQueue
.
main
)
.
sink
{
[
unowned
self
]
in
.
sink
{
[
unowned
self
]
in
screenView
.
c
ollectionView
.
isHidden
=
$0
.
count
<
1
screenView
.
topC
ollectionView
.
isHidden
=
$0
.
count
<
1
count
=
$0
.
count
count
=
$0
.
count
selectedElements
=
$0
selectedElements
=
$0
...
@@ -128,11 +129,11 @@ public final class CreateGroupController: UIViewController {
...
@@ -128,11 +129,11 @@ public final class CreateGroupController: UIViewController {
return
snapshot
return
snapshot
}
}
.
receive
(
on
:
DispatchQueue
.
main
)
.
receive
(
on
:
DispatchQueue
.
main
)
.
sink
{
[
unowned
self
]
in
c
ollectionDataSource
.
apply
(
$0
)
}
.
sink
{
[
unowned
self
]
in
topC
ollectionDataSource
.
apply
(
$0
)
}
.
store
(
in
:
&
cancellables
)
.
store
(
in
:
&
cancellables
)
viewModel
.
contacts
viewModel
.
contacts
.
map
{
contacts
in
.
map
{
contacts
->
NSDiffableDataSourceSnapshot
<
SectionId
,
Contact
>
in
var
snapshot
=
NSDiffableDataSourceSnapshot
<
SectionId
,
Contact
>
()
var
snapshot
=
NSDiffableDataSourceSnapshot
<
SectionId
,
Contact
>
()
let
sections
=
[
SectionId
()]
let
sections
=
[
SectionId
()]
snapshot
.
appendSections
(
sections
)
snapshot
.
appendSections
(
sections
)
...
@@ -141,7 +142,8 @@ public final class CreateGroupController: UIViewController {
...
@@ -141,7 +142,8 @@ public final class CreateGroupController: UIViewController {
}
}
.
receive
(
on
:
DispatchQueue
.
main
)
.
receive
(
on
:
DispatchQueue
.
main
)
.
sink
{
[
unowned
self
]
in
.
sink
{
[
unowned
self
]
in
tableDataSource
.
apply
(
$0
,
animatingDifferences
:
tableDataSource
.
snapshot
()
.
numberOfItems
>
0
)
let
animating
=
bottomCollectionDataSource
.
snapshot
()
.
numberOfItems
>
0
bottomCollectionDataSource
.
apply
(
$0
,
animatingDifferences
:
animating
)
}
.
store
(
in
:
&
cancellables
)
}
.
store
(
in
:
&
cancellables
)
screenView
.
searchComponent
.
textPublisher
screenView
.
searchComponent
.
textPublisher
...
@@ -161,7 +163,7 @@ public final class CreateGroupController: UIViewController {
...
@@ -161,7 +163,7 @@ public final class CreateGroupController: UIViewController {
coordinator
.
toGroupDrawer
(
coordinator
.
toGroupDrawer
(
with
:
count
+
1
,
with
:
count
+
1
,
from
:
self
,
{
(
name
,
welcome
)
in
from
:
self
,
{
(
name
,
welcome
)
in
viewModel
.
create
(
name
:
name
,
welcome
:
welcome
,
members
:
selectedElements
)
self
.
viewModel
.
create
(
name
:
name
,
welcome
:
welcome
,
members
:
self
.
selectedElements
)
}
}
)
)
}
.
store
(
in
:
&
cancellables
)
}
.
store
(
in
:
&
cancellables
)
...
@@ -172,15 +174,15 @@ public final class CreateGroupController: UIViewController {
...
@@ -172,15 +174,15 @@ public final class CreateGroupController: UIViewController {
}
}
}
}
extension
CreateGroupController
:
UI
Table
ViewDelegate
{
extension
CreateGroupController
:
UI
Collection
ViewDelegate
{
public
func
tableView
(
_
tableView
:
UITable
View
,
didSelect
Row
At
indexPath
:
IndexPath
)
{
public
func
collectionView
(
_
collectionView
:
UICollection
View
,
didSelect
Item
At
indexPath
:
IndexPath
)
{
if
let
contact
=
table
DataSource
.
itemIdentifier
(
for
:
indexPath
)
{
if
let
contact
=
bottomCollection
DataSource
.
itemIdentifier
(
for
:
indexPath
)
{
viewModel
.
didSelect
(
contact
:
contact
)
viewModel
.
didSelect
(
contact
:
contact
)
}
}
}
}
public
func
tableView
(
_
tableView
:
UITable
View
,
didDeselect
Row
At
indexPath
:
IndexPath
)
{
public
func
collectionView
(
_
collectionView
:
UICollection
View
,
didDeselect
Item
At
indexPath
:
IndexPath
)
{
if
let
contact
=
table
DataSource
.
itemIdentifier
(
for
:
indexPath
)
{
if
let
contact
=
bottomCollection
DataSource
.
itemIdentifier
(
for
:
indexPath
)
{
viewModel
.
didSelect
(
contact
:
contact
)
viewModel
.
didSelect
(
contact
:
contact
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Sources/ContactListFeature/Views/CreateGroupView.swift
+
18
−
13
View file @
09664e54
...
@@ -4,9 +4,20 @@ import SnapKit
...
@@ -4,9 +4,20 @@ import SnapKit
final
class
CreateGroupView
:
UIView
{
final
class
CreateGroupView
:
UIView
{
let
stackView
=
UIStackView
()
let
stackView
=
UIStackView
()
let
tableView
=
UITableView
()
let
searchComponent
=
SearchComponent
()
let
searchComponent
=
SearchComponent
()
lazy
var
collectionView
=
UICollectionView
(
frame
:
.
zero
,
collectionViewLayout
:
layout
)
lazy
var
topCollectionView
=
UICollectionView
(
frame
:
.
zero
,
collectionViewLayout
:
layout
)
lazy
var
bottomCollectionView
:
UICollectionView
=
{
var
config
=
UICollectionLayoutListConfiguration
(
appearance
:
.
plain
)
config
.
backgroundColor
=
Asset
.
neutralWhite
.
color
config
.
showsSeparators
=
false
let
layout
=
UICollectionViewCompositionalLayout
.
list
(
using
:
config
)
let
collectionView
=
UICollectionView
(
frame
:
bounds
,
collectionViewLayout
:
layout
)
collectionView
.
contentInset
=
.
init
(
top
:
15
,
left
:
0
,
bottom
:
0
,
right
:
0
)
return
collectionView
//tableView.setEditing(true, animated: true)
}()
let
layout
:
UICollectionViewFlowLayout
=
{
let
layout
:
UICollectionViewFlowLayout
=
{
let
layout
=
UICollectionViewFlowLayout
()
let
layout
=
UICollectionViewFlowLayout
()
...
@@ -20,24 +31,18 @@ final class CreateGroupView: UIView {
...
@@ -20,24 +31,18 @@ final class CreateGroupView: UIView {
super
.
init
(
frame
:
.
zero
)
super
.
init
(
frame
:
.
zero
)
backgroundColor
=
Asset
.
neutralWhite
.
color
backgroundColor
=
Asset
.
neutralWhite
.
color
tableView
.
separatorStyle
=
.
none
tableView
.
tintColor
=
Asset
.
brandPrimary
.
color
tableView
.
backgroundColor
=
Asset
.
neutralWhite
.
color
tableView
.
allowsMultipleSelectionDuringEditing
=
true
tableView
.
setEditing
(
true
,
animated
:
true
)
searchComponent
.
set
(
searchComponent
.
set
(
placeholder
:
"Search connections"
,
placeholder
:
"Search connections"
,
imageAtRight
:
UIImage
.
color
(
.
clear
)
imageAtRight
:
UIImage
.
color
(
.
clear
)
)
)
c
ollectionView
.
backgroundColor
=
Asset
.
neutralWhite
.
color
topC
ollectionView
.
backgroundColor
=
Asset
.
neutralWhite
.
color
c
ollectionView
.
contentInset
=
UIEdgeInsets
(
top
:
0
,
left
:
30
,
bottom
:
0
,
right
:
30
)
topC
ollectionView
.
contentInset
=
UIEdgeInsets
(
top
:
0
,
left
:
30
,
bottom
:
0
,
right
:
30
)
stackView
.
spacing
=
31
stackView
.
spacing
=
31
stackView
.
axis
=
.
vertical
stackView
.
axis
=
.
vertical
stackView
.
addArrangedSubview
(
c
ollectionView
)
stackView
.
addArrangedSubview
(
topC
ollectionView
)
stackView
.
addArrangedSubview
(
table
View
)
stackView
.
addArrangedSubview
(
bottomCollection
View
)
addSubview
(
stackView
)
addSubview
(
stackView
)
addSubview
(
searchComponent
)
addSubview
(
searchComponent
)
...
@@ -55,7 +60,7 @@ final class CreateGroupView: UIView {
...
@@ -55,7 +60,7 @@ final class CreateGroupView: UIView {
make
.
bottom
.
equalToSuperview
()
make
.
bottom
.
equalToSuperview
()
}
}
c
ollectionView
.
snp
.
makeConstraints
{
$0
.
height
.
equalTo
(
100
)
}
topC
ollectionView
.
snp
.
makeConstraints
{
$0
.
height
.
equalTo
(
100
)
}
}
}
required
init
?(
coder
:
NSCoder
)
{
nil
}
required
init
?(
coder
:
NSCoder
)
{
nil
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment