-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Added Dialogs #1021
Added Dialogs #1021
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this @DanielDahan but I would remove all the magic numbers and put them in private struct. Need to test this in real app.
@adamdahan private struct is a good idea, I would apply that. But I've seen @DanielDahan himself using magic numbers and some magic variables throughout all the framework :] |
@OrkhanAlikhanov @adamdahan I think that updating Material to no longer use any magic numbers would be ideal. |
Hey @DanielDahan, I actually started a while ago moving those magic numbers into a |
@OrkhanAlikhanov Thank you so much for this - I really like the code. I do have a question for you: Did you consider using the Card as the Dialog itself? Curious to know if there is a particular reason why you rolled out your own card like Dialog. Had you made an extension built on UIViewController or used a custom animated transition coordinator which allow cards to be presented modally - seems like the same task could been accomplished with less code and be more robust. Looking forward to your response :) Good work 👍 |
@adamdahan Let's discuss this at gitter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OrkhanAlikhanov Nicely done :) I looked through the code and tried the sample, all looks great. I am going to merge this and rework some parts to be better integrated with the framework. We will of course make sure to keep your credit as that is our protocol on our new site that is launching soon. Thank you!
@OrkhanAlikhanov There has been some development on DialogBuilder -> Dialog and line: What is the preferred way to subclass the dialog to have a custom feature in the dialog? Thanks! |
Yeah, that was design decision. There is no more DialogBuilder we removed it in favor of separate let vc = DialogController<AppDialogView>()
///configure vc.dialogView
present(vc, animated: true) |
Oh, so it's via the DialogController. No, that's perfectly fine, I just didn't know how to make it work, since it's a new undocumented feature in progress. Thanks a lot! |
The PR implements Material Design - Dialogs guideline and introduces 3 new classes:
DialogView
-UIView
subclass that implements dialog layout.DialogController
-UIViewController
subclass that managesDialogView
.DialogBuilder
- Delegate between developer andDialogController
(Dialog API).DialogView
Implements design and layout according to Material Design - Dialogs guideline
DialogController
DialogController
is used to present dialog view and manage user's interactions with it.Buttons
A standard dialog can contain three buttons at most. Those are positive, negative and neutral buttons. When user taps on one of those buttons, the dialog controller gets dismissed and corresponding event handler will be called.
Cancelable
DialogController
can be dismissed when user taps outside of the dialog (on the dimmed area). To enable that feature, setisCancelable
property totrue
. When user cancels the dialog (through tapping outside),didCancelHandler
property of the dialog controller will be called.Preventing dismiss
DialogVontroller
can be prevented from getting dismissed through user interaction. IfshouldDismissHandler
is set, then whenever dismissal happensshouldDismissHandler
will be called and that's where you can prevent dismissal. The handler will accept two arguments and must return aBool
indicating approval of dismiss.DialogView
)Button?
) that dismissal invoked through (nil
if dialog is cancelled).Dialog API
Dialog Api simplifies creation of
DialogController
, allowing developer to focus on more important things.Basic usage
Result
The
DialogController
that is generated byDialog
API can be retrieved by simply writing.controller
when desired properties are set (or even after dialog is shown).Advanced
Dialog
,DialogBuilder
andDialogController
is actually defined asThe generic way is just used to let developers work easily with the subclasses of
DialogView
.Subclassing
DialogView
Developers can subclass Material's
DialogView
to create their own custom dialogs.Then define
AppDialog
asAnd use it just like you would do
Dialog
More on customizing
There are 3 functions that is used by
DialogView
to determine its correct size and lay out its subviews:func titleAreaSizeThatFits(width: CGFloat) -> CGSize
func contentViewSizeThatFits(width: CGFloat) -> CGSize
func buttonAreaSizeThatFits(width: CGFloat) -> CGSize
If the overall size of the
DialogView
becomes more than the screen size of the device, thecontentView
will become scrollable.If you customize
titleArea
,contentView
orbuttonArea
, corresponding method should be overridden to return the size that is going to occupy and necessary laying out should be done in by overridinglayoutSubviews()