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

Added search bar component #69

Merged
merged 8 commits into from Nov 8, 2018
Merged

Added search bar component #69

merged 8 commits into from Nov 8, 2018

Conversation

ilyapuchka
Copy link
Contributor

This PR adds a simple component that contains UISearchBar.

Motivation

Sometimes it might be needed just to display a search bar in the cell without the luggage of UISearchViewController which might be hard sometimes to tweak to fit particular UX, and something that requires less customisation than UITextField to make it look like UISearchBar.

Alternatives considered

There is currently TextInput component in BentoKit but it kind of serves a different purpose and also requires quite some tweaking and style additions to make it fit this use case. Also UISearchBar is not a subclass of UITextField and have some extra features like showing cancel button and search icon out of the box (still could be done with TextInput but not without more changes to it).

UISearchViewController also does not fit here very well as it requires navigationItem and it can be tricky to make it work with DrawerKit used here (see screenshot)

Example

simulator screen shot - iphone xs max - 2018-11-06 at 19 40 20

@ilyapuchka ilyapuchka self-assigned this Nov 7, 2018
@mluisbrown mluisbrown added enhancement New feature or request ready for review Reviewers can now review the PR labels Nov 7, 2018
Copy link
Contributor

@mluisbrown mluisbrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ilyapuchka ilyapuchka changed the title [WIP] Added search bar component Added search bar component Nov 7, 2018

let searchBar = UISearchBar()

var textDidChange: Optional<(UISearchBar, String) -> Void> = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need the UISearchBar there?

Copy link
Contributor Author

@ilyapuchka ilyapuchka Nov 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to follow the signature of the delegate method. also it makes it easier to do things like dismiss keyboard when cancel is pressed (for some reason is not a default behaviour) without jumping through the hoops. it can always be ignored if not needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough

public init(
placeholder: String? = nil,
keyboardType: UIKeyboardType = .default,
didBeginEditing: Optional<(UISearchBar) -> Void> = nil,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dito


extension Component.Search {
public final class StyleSheet: BaseViewStyleSheet<View> {
public struct SearchBar: StyleSheetProtocol {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to the StyleSheets framework. And should be extended from ViewStyleSheet as UISearchBar is a subclass of UIView

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sergdort done 👍

Copy link
Contributor

@sergdort sergdort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions regarding closures and stylesheets 👍

@ilyapuchka
Copy link
Contributor Author

@sergdort I've addressed your comments

super.apply(to: element)
element.setTextInputBackgroundColor(color: backgroundColor ?? .clear,
height: height,
cornerRadius: cornerRadius)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because on UISearchBar one can only set the background image, not a colour.

Copy link
Contributor

@sergdort sergdort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just couple comments left

@ilyapuchka
Copy link
Contributor Author

@sergdort addressed 😉

@sergdort sergdort merged commit 07f73ec into master Nov 8, 2018
@sergdort sergdort deleted the search-bar-component branch November 8, 2018 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ready for review Reviewers can now review the PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants