Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Greish background #37

Closed
xjurko12 opened this issue Jul 31, 2020 · 3 comments
Closed

Greish background #37

xjurko12 opened this issue Jul 31, 2020 · 3 comments

Comments

@xjurko12
Copy link

Is it possible to somehow add background view which disable interaction with parent view?

@prashantAlgante
Copy link

@OfTheWolf one more point in this : interaction can be managed like when to enable and when to disable.

Use case is like : When opened at initial position then parent interaction is enabled and when opened further after initial position then we can disable parent interaction.

@thanhdolong
Copy link

I did greish background replicating from example. You can find it here

class MapsViewController: UIViewController {

    ....

    private func addBackDimmingBackView(below container: UIView){
            backView = PassThroughView()
            self.view.insertSubview(backView!, belowSubview: container)
            backView!.translatesAutoresizingMaskIntoConstraints = false
            backView!.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
            backView!.bottomAnchor.constraint(equalTo: container.topAnchor, constant: 10).isActive = true
            backView!.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
            backView!.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
        }
}

extension MapsViewController: UBottomSheetCoordinatorDelegate{
    
    func bottomSheet(_ container: UIView?, didPresent state: SheetTranslationState) {
        self.addBackDimmingBackView(below: container!)
        self.sheetCoordinator.addDropShadowIfNotExist()
        self.handleState(state)
    }

    func bottomSheet(_ container: UIView?, didChange state: SheetTranslationState) {
        handleState(state)
    }

    func bottomSheet(_ container: UIView?, finishTranslateWith extraAnimation: @escaping ((CGFloat) -> Void) -> Void) {
        extraAnimation({ percent in
            self.backView?.backgroundColor = UIColor.black.withAlphaComponent(percent/100 * 0.8)
        })
    }
    
    func handleState(_ state: SheetTranslationState){
        switch state {
        case .progressing(_, let percent):
            self.backView?.backgroundColor = UIColor.black.withAlphaComponent(percent/100 * 0.8)
        case .finished(_, let percent):
            self.backView?.backgroundColor = UIColor.black.withAlphaComponent(percent/100 * 0.8)
        default:
            break
        }
    }
}

@OfTheWolf
Copy link
Owner

@xjurko12

Instead of PassThroughView use UIView as below.

private func addBackDimmingBackView(below container: UIView){
      backView = UIView() // PassThroughView()
      self.view.insertSubview(backView!, belowSubview: container)
      backView!.translatesAutoresizingMaskIntoConstraints = false
      backView!.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
      backView!.bottomAnchor.constraint(equalTo: container.topAnchor, constant: 10).isActive = true
      backView!.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
      backView!.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants