danielsaidi / Sheeeeeeeeet

Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.
MIT License
1.74k stars 111 forks source link

new appearance #89

Closed marinofaggiana closed 5 years ago

marinofaggiana commented 5 years ago

Hi, thanks for your library, with the new appearance (1.4.0) how I can modify a titleColor for a single item ?

danielsaidi commented 5 years ago

Hi @marinofaggiana

The new appearance "engine" relies heavily on the built-in iOS appearance proxy capabilities, with some exceptions where this wasn't applicable.

This means that the easiest way to adjust the appearance of items is to have an item class with a corresponding cell class for each item type, and apply any customizations to that cell's appearance proxy. You can override any of the built-in item types and perform any adjustments that you need.

Is this applicable to your situation?

marinofaggiana commented 5 years ago

Hi @danielsaidi, thanks for your reply, I need change only a single item (no proxy), look this (old) code :

var items = [ActionSheetItem]()
let appearanceDelete = ActionSheetItemAppearance.init()
appearanceDelete.textColor = UIColor.red

items.append(ActionSheetItem(title: NSLocalizedString("_edit_comment_", comment: ""), value: 0, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "edit"), width: 50, height: 50, color: NCBrandColor.sharedInstance.icon)))
let itemDelete = ActionSheetItem(title: NSLocalizedString("_delete_comment_", comment: ""), value: 1, image: CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 50, height: 50, color: .red))
itemDelete.customAppearance = appearanceDelete
items.append(itemDelete)
items.append(ActionSheetCancelButton(title: NSLocalizedString("_cancel_", comment: "")))

Only the item appearanceDelete must be red color, but now the "itemDelete.customAppearance = appearanceDelete" is deprecated.

Thanks m.

danielsaidi commented 5 years ago

Things are easier in the upcoming 2.1.0 version, but if you want to achieve this using the old version, I'd recommend that you create a subclass and style it separately.

For instance, I think adding the following item and cell classes should do the trick (I just improvise the code so it may not work right away):

class ActionSheetDeleteItem: ActionSheetItem {
    open func cell(for tableView: UITableView) -> ActionSheetItemCell {
        return ActionSheetDeleteItemCell(style: cellStyle, reuseIdentifier: cellReuseIdentifier)
    }
}

class ActionSheetDeleteItemCell: ActionSheetItemCell {}

You could then style it as such:

ActionSheetDeleteItemCell.appearance().titleColor = .red

Then just create an ActionSheetDeleteItem instead of a regular ActionSheetItem.

It's a bit cumbersome, but I think this should work.

marinofaggiana commented 5 years ago

Thx @danielsaidi, thanks for your answer, we remain with the message of deprecated in wait of the 2.1.0. I think that the appearance proxy for this type of library is not the best choice. Thanks for your job.

danielsaidi commented 5 years ago

I think that a custom subclass is the way to go in your case - it's pretty straightforward and I use it extensively myself. I am just about to release 2.1.0 as a beta, so I'd love to hear your feedback regarding the new appearance model. Closing this for now, but feel free to reopen it if you think that subclassing doesn't solve your needs.

marinofaggiana commented 5 years ago

Hi @danielsaidi I have see that is available your version 2.1.0, good, how I can resolve my issue ?

danielsaidi commented 5 years ago

You can use the appearance proxy-based properties on a cell type or a single cell instance.

For instance, if you subclass any of the built-in types (e.g. create a DeleteCommentItem with a matching DeleteCommentItemCell), you could style that item's appearance like this:

DeleteCommentItemCell.appearance(). cell.titleColor = .red

However, if you have such a cell instance, you can just set:

cell.titleColor = .red

I hope this makes sense.

marinofaggiana commented 5 years ago

ok @danielsaidi I have used

class ActionSheetDeleteItem: ActionSheetItem {
    open func cell(for tableView: UITableView) -> ActionSheetItemCell {
        return ActionSheetDeleteItemCell(style: cellStyle, reuseIdentifier: cellReuseIdentifier)
    }
}

class ActionSheetDeleteItemCell: ActionSheetItemCell {}

Thanks

danielsaidi commented 5 years ago

Ok, and that works for you?

marinofaggiana commented 5 years ago

Yes, works, I don't like this approach but works.

danielsaidi commented 5 years ago

It's going to be easier in 3.0.

marinofaggiana commented 4 years ago

Hi @danielsaidi you wrote:

It's going to be easier in 3.0.

how ?

Thanks m.

danielsaidi commented 4 years ago

I'm afraid I focused on separating the menu model from the action sheet, and that the action sheet logic are more or less the same. So it works like before, which you didn't like.