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

Multiple button support? #19

Closed
HackShitUp opened this issue May 23, 2018 · 20 comments
Closed

Multiple button support? #19

HackShitUp opened this issue May 23, 2018 · 20 comments
Assignees
Labels
enhancement New feature or request

Comments

@HackShitUp
Copy link

HackShitUp commented May 23, 2018

Is there a way to display multiple buttons on top of each other in such a way that they're stacked in the view? I briefly saw the documentation and saw that action-methods are supported, but how would one pass n-number of buttons, each with different delegate methods?

@huri000
Copy link
Owner

huri000 commented May 23, 2018

Hi,
You can use EKProperty.ButtonBarContent as data source of EKButtonBarView.
EKButtonBarView receives EKProperty.ButtonBarContent instance and inits itself accordingly.
If there are more than 2 buttons - they automatically stacked vertically as in the alert presets in the demo app.

EKProperty.ButtonBarContent instance contains an array of EKProperty.ButtonContent - one for each button. Each has an action.
More than one action (.touchUpInside) is currently not supported. But i'm open to suggestions if that's not enough IYO :)

@HackShitUp
Copy link
Author

HackShitUp commented May 23, 2018

So I tried what you suggested and I think what I'm trying to achieve is to display multiple buttons in this format:
img_2571

I tried the following:

        var attributes = EKAttributes.centerFloat
        attributes.hapticFeedbackType = .success
        attributes.displayDuration = .infinity
        attributes.shadow = .active(with: .init(color: .black, opacity: 0.3, radius: 8, offset: .zero))
        attributes.screenInteraction = .dismiss
        attributes.entryInteraction = .absorbTouches
        attributes.scroll = .enabled(swipeable: true, pullbackAnimation: .jolt)
        attributes.roundCorners = .all(radius: 8)
        attributes.entranceAnimation = .init(translate: .init(duration: 0.7, spring: .init(damping: 0.7, initialVelocity: 0)), scale: .init(from: 0.7, to: 1, duration: 0.4, spring: .init(damping: 1, initialVelocity: 0)))
        attributes.exitAnimation = .init(translate: .init(duration: 0.2))
        attributes.popBehavior = .animated(animation: .init(translate: .init(duration: 0.35)))
        attributes.positionConstraints.size = .init(width: .offset(value: 20), height: .intrinsic)
        attributes.statusBarStyle = .default
        attributes.screenBackground = .visualEffect(style: .prominent)
        attributes.entryBackground = .visualEffect(style: .dark)

        let buttonOne = EKProperty.ButtonContent.init(label: EKProperty.LabelContent.init(text: "One", style: .init(font: UIFont.bold(size: 12), color: UIColor.babyBlue(), alignment: .center)), backgroundColor: .white) {
            print("One!")
        }
        
        let buttonTwo = EKProperty.ButtonContent.init(label: EKProperty.LabelContent.init(text: "Two", style: .init(font: UIFont.bold(size: 12), color: UIColor.babyBlue(), alignment: .center)), backgroundColor: .white) {
            print("Two!")
        }

        let buttonContent = EKProperty.ButtonBarContent.init(with: buttonOne, buttonTwo, separatorColor: .iceGray(), expandAnimatedly: true)
        let buttonBarView = EKButtonBarView.init(with: buttonContent)
        SwiftEntryKit.display(entry: buttonBarView, using: attributes)

But it displays this instead and I can't see the contents of the button:
img_2572

@HackShitUp
Copy link
Author

Could this only be achieved with EKAlertMessageView?

@huri000
Copy link
Owner

huri000 commented May 23, 2018

That's an interesting point.
EKAlertMessageView only provides UI infrastructure for using it. It uses expandAnimately to expand the buttons by changing inner priorities.
Since EKButtonBarView doesn't handle the expansion itself, you need to do it yourself by doing:

buttonBarView.expand()
buttonBarView.layoutIfNeeded()

I should move the expand logic to the button bar view itself sometime soon. I have no doubt that logic should be there and not in its container.

@HackShitUp
Copy link
Author

HackShitUp commented May 23, 2018

Right, I was using the UI debugger on Xcode and setting the EKAttributes from

attributes.positionConstraints.size = .init(width: .offset(value: 20), height: .intrinsic)

to

attributes.positionConstraints.size = .init(width: .offset(value: 20), height: EKAttributes.PositionConstraints.Edge.constant(value: 100))

displays the buttons, but not vertically stacked with a third button. Also, using

buttonBarView.expand()

logs this error: 'expand' is inaccessible due to 'internal' protection level

For now, because this project supports custom XIBS, I think I'm just going to do that for multiple buttons. 👍
Thank you!

@HackShitUp
Copy link
Author

By the way, I think this is the best presentation libraries out there on this planet 👍

@huri000
Copy link
Owner

huri000 commented May 23, 2018

Thanks a lot! ^^
I'll review the button bar view anyway and expose more of its methods.

@huri000 huri000 reopened this Jun 5, 2018
@huri000 huri000 self-assigned this Jun 6, 2018
@huri000 huri000 added the enhancement New feature or request label Jun 6, 2018
@huri000
Copy link
Owner

huri000 commented Jun 6, 2018

I revised EKButtonBarView's expand method to contain all the expansion related logic.
Now, you basically only need to create an EKProperty.ButtonBarContent instance, initEKButtonBarView using it. Then call display method on SwiftEntryKit using your attributes.
It's available on version 0.3.3. Enjoy! ^^

@huri000
Copy link
Owner

huri000 commented Jun 8, 2018

@HackShitUp
B.T.W: You still need to invoke expand on the EKButtonBarView instance.
I believe the requirements specified in this issue are satisfied. Let me know if you think otherwise.
Thanks!

@huri000 huri000 closed this as completed Jun 14, 2018
@Smiller193
Copy link

@huri000 can I see an example of this please

@huri000
Copy link
Owner

huri000 commented Jan 13, 2019

@Smiller193 - The example project contains everything you need to know. :-)

@Smiller193
Copy link

@huri000 even with the multiple button support

@Smiller193
Copy link

I just want a center popup example with multiple buttons

@Smiller193
Copy link

@huri000 I see the example with one button but not two

@huri000
Copy link
Owner

huri000 commented Jan 13, 2019

Have you tried the Service Rating preset?

@Smiller193
Copy link

umm let me try

@HackShitUp
Copy link
Author

@huri000 I think if you could provide an example in the README, it could really help out

@huri000
Copy link
Owner

huri000 commented Jan 15, 2019 via email

@SumitSMARTER
Copy link

SumitSMARTER commented Jun 9, 2020

@huri000 I am new to Swift and was trying to use your Library, what I was trying to achieve is the same thing which @HackShitUp was trying to accomplish, multiple buttons in the EKPopUpmessage.
I checked the Rating example but, what I perceive that it has buttonBarContent: <#T##EKProperty.ButtonBarContent#>), but the PopUp msg does not have that property, EKPopUpMessage(themeImage: <#T##EKPopUpMessage.ThemeImage?#>,
title: <#T##EKProperty.LabelContent#>,
description: <#T##EKProperty.LabelContent#>,
button: <#T##EKProperty.ButtonContent#>,
action<#T##EKPopUpMessage.EKPopUpMessageAction##EKPopUpMessage.EKPopUpMessageAction##() -> ()#>)

Please help how to accomplish this, I am ClueLess, if there is any example, it would be much Helpful.

Thanks.

@swarajsinghdev
Copy link

still not any solution

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

No branches or pull requests

5 participants