From 0aa9250816332e4a16aa97a4ea837009a9ac3dfc Mon Sep 17 00:00:00 2001 From: Vittorio Cellucci Date: Mon, 7 Nov 2022 06:20:10 -0500 Subject: [PATCH] fix: cleanup shadows --- ios/ColumnResizerView.swift | 70 ++++++++++++--------------- ios/HorizontalScrolViewDelegate.swift | 21 +++----- ios/TableView.swift | 10 +++- 3 files changed, 46 insertions(+), 55 deletions(-) diff --git a/ios/ColumnResizerView.swift b/ios/ColumnResizerView.swift index a1f719ce..c19a1e18 100644 --- a/ios/ColumnResizerView.swift +++ b/ios/ColumnResizerView.swift @@ -20,7 +20,7 @@ class ColumnResizerView: UIView { weak var button: ResizerButtonView? weak var horizontalScrollView: UIScrollView? weak var containerView: ContainerView? - + init( _ columnWidths: ColumnWidths, index: Int, bindTo bindedTableView: TableView) { self.columnWidths = columnWidths self.tableView = bindedTableView @@ -30,7 +30,7 @@ class ColumnResizerView: UIView { self.isUserInteractionEnabled = true createButton() } - + fileprivate func createButton() { let button = ResizerButtonView() button.translatesAutoresizingMaskIntoConstraints = false @@ -44,7 +44,7 @@ class ColumnResizerView: UIView { ] NSLayoutConstraint.activate(constraints) self.addConstraints(constraints) - + let panGesture = UIPanGestureRecognizer(target: self, action: #selector(self.handleGesture(_:))) panGesture.minimumNumberOfTouches = 1 panGesture.maximumNumberOfTouches = 1 @@ -52,41 +52,31 @@ class ColumnResizerView: UIView { button.addGestureRecognizer(panGesture) self.button = button } - + override func touchesBegan(_ touches: Set, with event: UIEvent?) { - super.touchesBegan(touches, with: event) - if let touch = touches.first { - if touch.view == self.button { - pressed = true - setNeedsDisplay() - } - } - } - - override func touchesEnded(_ touches: Set, with event: UIEvent?) { - super.touchesEnded(touches, with: event) - if let touch = touches.first { - if touch.view == self.button { - pressed = false - setNeedsDisplay() - } + super.touchesBegan(touches, with: event) + if let touch = touches.first { + if touch.view == self.button { + pressed = true + setNeedsDisplay() } } - - override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { - let view = super.hitTest(point, with: event) - if view == button { - return view - } - if view == self { - return nil + } + + override func touchesEnded(_ touches: Set, with event: UIEvent?) { + super.touchesEnded(touches, with: event) + if let touch = touches.first { + if touch.view == self.button { + pressed = false + setNeedsDisplay() } - return view } - + } + @objc func handleGesture(_ sender: UIPanGestureRecognizer) { switch sender.state { case .began: + pressed = true self.setNeedsDisplay() case .changed: let point = sender.translation(in: self) @@ -109,14 +99,14 @@ class ColumnResizerView: UIView { break } } - + func didPan(_ translation: CGPoint) { guard let tableView = self.tableView else { return } guard let data = tableView.dataCollectionView else { return } if data.updateSize(translation, withColumn: index) { columnWidths.resize(index: index, by: translation) self.centerConstraint.constant = self.centerConstraint.constant + translation.x - + tableView.grow(by: translation.x) if let adjacentTable = self.adjacentTable { adjacentTable.dymaniceLeadingAnchor.constant = columnWidths.columnWidths[0] @@ -129,7 +119,7 @@ class ColumnResizerView: UIView { tableView.layoutIfNeeded() } } - + func didEndPand() { columnWidths.saveToStorage() if let scrollView = self.horizontalScrollView { @@ -139,23 +129,23 @@ class ColumnResizerView: UIView { } } } - + func setPosition(_ x: Double) { self.centerConstraint.constant = x } - + override func draw(_ rect: CGRect) { let x = rect.origin.x + rect.width / 2 linePath.removeAllPoints() linePath.move(to: CGPoint(x: x, y: 0)) linePath.addLine(to: CGPoint(x: x, y: rect.height)) linePath.lineWidth = 1 - + let color = pressed ? .black : borderColor color.setStroke() linePath.stroke() } - + func setHeight(_ newVal: Double) { guard let button = button else { return } button.heightConstraint.constant = newVal @@ -166,16 +156,16 @@ class ColumnResizerView: UIView { if let headerView = self.headerView { headerView.updateSize(translation, withColumn: index) } - + } func updateTotals(_ translation: CGPoint) { if let totals = self.totalsView { totals.updateSize(translation, withColumn: index) } } - + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + } diff --git a/ios/HorizontalScrolViewDelegate.swift b/ios/HorizontalScrolViewDelegate.swift index a6486762..5c909187 100644 --- a/ios/HorizontalScrolViewDelegate.swift +++ b/ios/HorizontalScrolViewDelegate.swift @@ -7,7 +7,6 @@ import Foundation class HorizontalScrollViewDelegate: NSObject, UIScrollViewDelegate { - weak var tableView: TableView? weak var totalsView: UIView? weak var headersView: UIView? @@ -25,7 +24,7 @@ class HorizontalScrollViewDelegate: NSObject, UIScrollViewDelegate { guard let tableView = self.tableView else { return } guard let columnWidths = self.columnWidths else { return } guard let grabber = self.grabber else { return } - let shadowOffsetX = clampScrollPos(scrollView.contentOffset.x) + let shadowOffsetX = clampScrollPos(Float(scrollView.contentOffset.x)) let rawX = scrollView.contentOffset.x if rawX <= 0 { @@ -39,22 +38,16 @@ class HorizontalScrollViewDelegate: NSObject, UIScrollViewDelegate { } let offset = shadowOffsetX/100.0 - updateShadow(tableView, offset: offset) - - if let totalsView = totalsView { - updateShadow(totalsView, offset: offset) - } - - if let headersView = headersView { - updateShadow(headersView, offset: offset) - } + updateShadow(offset: offset) + } - func clampScrollPos(_ x: CGFloat) -> CGFloat { + func clampScrollPos(_ x: Float) -> Float { return min(100.0, x) } - func updateShadow(_ view: UIView, offset: CGFloat) { - view.addLeftShadow(radius: 2, opacity: offset, offset: offset) + func updateShadow(offset: Float) { + tableView?.setShadow(offset: min(offset, 0.4)) + tableView?.setNeedsDisplay() } } diff --git a/ios/TableView.swift b/ios/TableView.swift index 0da69517..3f692ddb 100644 --- a/ios/TableView.swift +++ b/ios/TableView.swift @@ -15,6 +15,8 @@ class TableView: UIView { weak var lastGrabber: LastColumnResizer? weak var firstGrabber: ColumnResizerView? weak var adjacentTable: TableView? + var needsShadow = false + var shaddowOffset:Float = 0.0 var isFirst = false var dynamicWidth = NSLayoutConstraint() var dymaniceLeadingAnchor = NSLayoutConstraint() @@ -97,5 +99,11 @@ class TableView: UIView { resizer()?.setHeight(height) } } - + + func setShadow(offset: Float) { + self.layer.shadowOffset = CGSize(width: 1, height: 1) + self.layer.shadowRadius = 2 + self.layer.shadowColor = UIColor.gray.cgColor + self.layer.shadowOpacity = offset + } }