Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
1
1weather
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dmitriy Stepanets
1weather
Commits
687ec259
Commit
687ec259
authored
Jul 16, 2021
by
Dmitriy Stepanets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chnaged shorts overlay image rendering to fullscreen
parent
35fbac87
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
9 deletions
+59
-9
1Weather/UI/View controllers/Shorts/Cells/ShortsItemCell.swift
+39
-3
1Weather/UI/View controllers/Shorts/ShortsViewController.swift
+20
-6
No files found.
1Weather/UI/View controllers/Shorts/Cells/ShortsItemCell.swift
View file @
687ec259
...
...
@@ -70,10 +70,41 @@ class ShortsItemCell: UITableViewCell {
currentShorts
=
shortsItem
if
let
backgroundImage
=
shortsItem
.
getOverlayImage
(
for
:
tableWidth
)
{
Nuke
.
loadImage
(
with
:
backgroundImage
.
url
,
into
:
backgroundImageView
)
Nuke
.
loadImage
(
with
:
backgroundImage
.
url
,
into
:
backgroundImageView
)
{[
weak
self
]
result
in
guard
let
self
=
self
else
{
return
}
switch
result
{
case
.
success
(
let
imageResponse
):
onMain
{
self
.
backgroundImageView
.
image
=
imageResponse
.
image
self
.
ctaButton
.
isHidden
=
false
self
.
likeButton
.
isHidden
=
false
//Update ImageView size
let
aspect
=
imageResponse
.
image
.
size
.
width
/
imageResponse
.
image
.
size
.
height
self
.
backgroundImageView
.
snp
.
remakeConstraints
{
remake
in
remake
.
left
.
top
.
right
.
equalToSuperview
()
remake
.
bottom
.
equalToSuperview
()
.
priority
(
.
medium
)
remake
.
width
.
equalTo
(
self
.
backgroundImageView
.
snp
.
height
)
.
multipliedBy
(
aspect
)
}
if
let
cachedColor
=
self
.
delegate
?
.
averageColor
(
forImage
:
imageResponse
.
image
,
identifier
:
backgroundImage
.
url
.
absoluteString
)
{
self
.
contentView
.
backgroundColor
=
cachedColor
}
else
{
self
.
contentView
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
}
}
default
:
self
.
ctaButton
.
isHidden
=
true
self
.
likeButton
.
isHidden
=
true
}
}
}
else
{
backgroundImageView
.
backgroundColor
=
UIColor
.
lightGray
self
.
ctaButton
.
isHidden
=
true
self
.
likeButton
.
isHidden
=
true
contentView
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
}
UIView
.
performWithoutAnimation
{
...
...
@@ -133,10 +164,13 @@ class ShortsItemCell: UITableViewCell {
//MARK:- Prepare
private
extension
ShortsItemCell
{
func
prepareForImageOnly
()
{
contentView
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
backgroundImageView
.
contentMode
=
.
scaleAspectFit
contentView
.
addSubview
(
backgroundImageView
)
backgroundImageView
.
snp
.
makeConstraints
{
make
in
make
.
edges
.
equalToSuperview
()
make
.
left
.
top
.
right
.
equalToSuperview
()
make
.
bottom
.
equalToSuperview
()
.
priority
(
.
medium
)
make
.
width
.
equalTo
(
backgroundImageView
.
snp
.
height
)
.
multipliedBy
(
1
)
}
}
...
...
@@ -228,6 +262,7 @@ private extension ShortsItemCell {
}
func
prepareActionButtons
()
{
likeButton
.
isHidden
=
true
likeButton
.
addTarget
(
self
,
action
:
#selector(
handleLikeButton
)
,
for
:
.
touchUpInside
)
likeButton
.
setImage
(
UIImage
(
named
:
"like_outline"
),
for
:
.
normal
)
likeButton
.
backgroundColor
=
ThemeManager
.
currentTheme
.
baseBackgroundColor
...
...
@@ -239,6 +274,7 @@ private extension ShortsItemCell {
likeButton
.
layer
.
shadowOpacity
=
0.3
contentView
.
addSubview
(
likeButton
)
ctaButton
.
isHidden
=
true
ctaButton
.
addTarget
(
self
,
action
:
#selector(
handleCtaButton
)
,
for
:
.
touchUpInside
)
ctaButton
.
backgroundColor
=
.
clear
ctaButton
.
layer
.
borderColor
=
UIColor
(
hex
:
0xDDDDDD
)
.
cgColor
...
...
1Weather/UI/View controllers/Shorts/ShortsViewController.swift
View file @
687ec259
...
...
@@ -266,10 +266,10 @@ extension ShortsViewController: UITableViewDataSource {
//MARK:- UITableView Delegate
extension
ShortsViewController
:
UITableViewDelegate
{
func
tableView
(
_
tableView
:
UITableView
,
heightForRowAt
indexPath
:
IndexPath
)
->
CGFloat
{
if
let
image
=
viewModel
.
shorts
[
indexPath
.
row
]
.
getOverlayImage
(
for
:
tableView
.
frame
.
width
)
{
let
aspectRatio
=
CGFloat
(
image
.
width
)
/
CGFloat
(
image
.
height
)
return
tableView
.
bounds
.
width
/
aspectRatio
}
//
if let image = viewModel.shorts[indexPath.row].getOverlayImage(for: tableView.frame.width) {
//
let aspectRatio = CGFloat(image.width) / CGFloat(image.height)
//
return tableView.bounds.width / aspectRatio
//
}
return
tableView
.
bounds
.
height
}
...
...
@@ -355,13 +355,27 @@ extension ShortsViewController: ViewModelDelegate {
//MARK:- ShortsItemCell Delegate
extension
ShortsViewController
:
ShortsItemCellDelegate
{
private
func
bottomPart
(
of
sourceImage
:
UIImage
)
->
UIImage
?
{
let
dy
:
CGFloat
=
10
//10pt from bottom
let
area
=
CGRect
(
x
:
0
,
y
:
sourceImage
.
size
.
height
-
dy
,
width
:
sourceImage
.
size
.
width
,
height
:
dy
)
guard
let
crop
=
sourceImage
.
cgImage
?
.
cropping
(
to
:
area
)
else
{
return
nil
}
return
UIImage
(
cgImage
:
crop
,
scale
:
UIScreen
.
main
.
scale
,
orientation
:
.
up
)
}
func
averageColor
(
forImage
image
:
UIImage
,
identifier
:
String
)
->
UIColor
?
{
if
let
cachedColor
=
self
.
averageColorCache
[
identifier
]
{
return
cachedColor
}
else
{
if
let
color
=
image
.
averageColor
{
self
.
averageColorCache
[
identifier
]
=
color
.
isDarkColor
?
color
:
color
.
darker
(
by
:
30
)
if
let
bottomPartImage
=
self
.
bottomPart
(
of
:
image
),
let
color
=
bottomPartImage
.
averageColor
{
self
.
averageColorCache
[
identifier
]
=
color
return
color
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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