Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public class BrowserAddressToolbar: UIView,
private func configureUX(config: AddressToolbarUXConfiguration,
toolbarPosition: AddressToolbarPosition) {
locationContainer.layer.cornerRadius = config.toolbarCornerRadius
locationContainer.updateShadowOpacityBasedOn(scrollAlpha: config.scrollAlpha)
dividerWidthConstraint?.constant = config.browserActionsAddressBarDividerWidth
let locationViewPaddings = config.locationViewVerticalPaddings(addressBarPosition: toolbarPosition)
toolbarBottomConstraint?.constant = -locationViewPaddings.bottom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,35 @@ final class LocationContainer: UIView, ThemeApplicable {
static let shadowOffset = CGSize(width: 0, height: 2)
}

private var theme: Theme?

override public func layoutSubviews() {
super.layoutSubviews()
init() {
super.init(frame: .zero)
setupShadow()
}

guard let theme else { return }
setupShadow(theme: theme)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func setupShadow(theme: Theme) {
override func layoutSubviews() {
super.layoutSubviews()
layer.shadowPath = UIBezierPath(roundedRect: bounds, cornerRadius: layer.cornerRadius).cgPath
}

private func setupShadow() {
layer.shadowRadius = UX.shadowRadius
layer.shadowOffset = UX.shadowOffset
layer.shadowColor = theme.colors.shadowStrong.cgColor
layer.shadowOpacity = UX.shadowOpacity
layer.masksToBounds = false
}

func updateShadowOpacityBasedOn(scrollAlpha: CGFloat) {
let targetOpacity = scrollAlpha.isZero ? 0 : UX.shadowOpacity
guard layer.shadowOpacity != targetOpacity else { return }
layer.shadowOpacity = targetOpacity
}

// MARK: - ThemeApplicable
public func applyTheme(theme: Theme) {
setupShadow(theme: theme)
self.theme = theme
func applyTheme(theme: Theme) {
layer.shadowColor = theme.colors.shadowStrong.cgColor
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class LocationView: UIView,
static let iconAnimationTime: CGFloat = 0.1
static let iconAnimationDelay: CGFloat = 0.03
static let bottomAddressBarYoffset: CGFloat = -28
static let bottomAddressBarYoffsetForDefaultScale: CGFloat = -10
static let topAddressBarYoffset: CGFloat = 26
static let smallScale: CGFloat = 0.7
static let identityResetAnimationDuration: TimeInterval = 0.2
Expand Down Expand Up @@ -159,7 +160,11 @@ final class LocationView: UIView,
delegate: delegate
)

applyToolbarAlphaIfNeeded(alpha: uxConfig.scrollAlpha, barPosition: addressBarPosition)
applyToolbarAlphaIfNeeded(
alpha: uxConfig.scrollAlpha,
barPosition: addressBarPosition,
isKeyboardVisible: config.shouldShowKeyboard
)
configureLockIconButton(config)
configureURLTextField(config)
configureA11y(config)
Expand Down Expand Up @@ -395,10 +400,14 @@ final class LocationView: UIView,
}

// MARK: - LocationView Scaling
private func shrinkLocationView(barPosition: AddressToolbarPosition) {
private func shrinkLocationView(barPosition: AddressToolbarPosition, isKeyboardVisible: Bool) {
let isiPad = UIDevice.current.userInterfaceIdiom == .pad
let yOffset: CGFloat = (barPosition == .bottom && !isiPad) ? UX.bottomAddressBarYoffset : UX.topAddressBarYoffset
transform = CGAffineTransform(scaleX: UX.smallScale, y: UX.smallScale).translatedBy(x: 0, y: yOffset)
let scaledTransformation = CGAffineTransform(scaleX: UX.smallScale, y: UX.smallScale).translatedBy(x: 0, y: yOffset)
transform = isKeyboardVisible ? CGAffineTransform(
translationX: 0,
y: UX.bottomAddressBarYoffsetForDefaultScale
) : scaledTransformation
urlTextField.isUserInteractionEnabled = false
}

Expand All @@ -416,11 +425,11 @@ final class LocationView: UIView,
)
}

private func applyToolbarAlphaIfNeeded(alpha: CGFloat, barPosition: AddressToolbarPosition) {
private func applyToolbarAlphaIfNeeded(alpha: CGFloat, barPosition: AddressToolbarPosition, isKeyboardVisible: Bool) {
guard scrollAlpha != alpha else { return }
scrollAlpha = alpha
if scrollAlpha.isZero {
shrinkLocationView(barPosition: barPosition)
shrinkLocationView(barPosition: barPosition, isKeyboardVisible: isKeyboardVisible)
} else {
restoreLocationViewSize()
}
Expand Down
Loading