GithubHelp home page GithubHelp logo

isabella232 / yoshi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from minima/yoshi

0.0 0.0 0.0 15.32 MB

A convenient wrapper around the UI code that is often needed for displaying debug menus.

License: MIT License

Ruby 8.91% Objective-C 1.46% Swift 88.79% Makefile 0.85%

yoshi's Introduction

Yoshi

Travis build status Cocoapods Compatible Platform Docs Carthage compatible

Description

A helpful companion for your iOS app.

Yoshi is a convenient wrapper around the UI code that is often needed for displaying debug menus. Out of the box, Yoshi provides easy-to-implement date, list and custom menus.

iPhone

Yoshi.gif

iPad

Yoshi_iPad.gif

Requirements

  • iOS 8.0+
  • Xcode 8.0+

Installation

CocoaPods

Yoshi is available through CocoaPods. To install it, simply add the following line to your Podfile:

Swift 3.0
pod "Yoshi"
Swift 2.3
pod 'Yoshi', '1.1.1'

Carthage

You can also add Yoshi to your project using Carthage. Add the following to your Cartfile:

github "prolificinteractive/Yoshi"

Usage

Yoshi can be set up to display any sort of menu as long as the menu object conforms to YoshiMenu. Yoshi comes with two built-in menus: list menu and date menu.

List Menu

To display a list menu, create two types that conform to YoshiTableViewMenu and YoshiTableViewMenuItem protocols respectively.

struct TableViewMenu: YoshiTableViewMenu {

    var title: String
    var subtitle: String?
    var displayItems: [YoshiTableViewMenuItem]
    var didSelectDisplayItem: (displayItem: YoshiTableViewMenuItem) -> ()

}

internal final class MenuItem: YoshiTableViewMenuItem {

    let name: String
    var selected: Bool

    init(name: String,
         selected: Bool = false) {
        self.name = name
        self.selected = selected
    }

}

Then, set up the menu and present it using Yoshi.

let production = MenuItem(name: "Production")
let staging = MenuItem(name: "Staging")
let qa = MenuItem(name: "QA", selected: true)
let environmentItems: [YoshiTableViewMenuItem] = [production, staging, qa]

let tableViewMenu = TableViewMenu(title: "Environment",
  subtitle: nil,
  displayItems: environmentItems,
  didSelectDisplayItem: { (displayItem) in
    // Switch environment here
})

Yoshi.setupDebugMenu([tableViewMenu])

// Invoke Yoshi
Yoshi.show()

Yoshi will take care of managing selections and call back the convenient closure function when a new selection is made.

Date Selector Menu

Similarly, to present a date selector menu, create a type that conforms to YoshiDateSelectorMenu protocol

internal final class DateSelector: YoshiDateSelectorMenu {

    var title: String
    var subtitle: String?
    var selectedDate: NSDate
    var didUpdateDate: (dateSelected: NSDate) -> ()

    init(title: String,
         subtitle: String? = nil,
         selectedDate: NSDate = NSDate(),
         didUpdateDate: (NSDate) -> ()) {
        self.title = title
        self.subtitle = subtitle
        self.selectedDate = selectedDate
        self.didUpdateDate = didUpdateDate
    }

}

and present it using the same functions.

let dateSelectorMenu = DateSelector(title: "Environment Date",
    subtitle: nil,
    didUpdateDate: { (dateSelected) in
      // Do something with the selected date here
})

Yoshi.setupDebugMenu([dateSelectorMenu])
Yoshi.show()

Custom Menu

Yoshi can also be configured to display custom menus which can be used for triggering events or presenting view controllers.

For example, we can invoke Instabug when a custom menu is selected.

private struct CustomMenu: YoshiMenu {

    let title: String
    let subtitle: String?
    let completion: () -> ()

    func execute() -> YoshiActionResult {
        return .AsyncAfterDismissing(completion)
    }

}

Instabug.startWithToken("abcdefghijklmnopqrstuvwxyz", invocationEvent: .None)
Instabug.setDefaultInvocationMode(.BugReporter)

let instabugMenu = CustomMenu(title: "Start Instabug",
    subtitle: nil,
    completion: {
        Instabug.invoke()
    })

Yoshi.setupDebugMenu([instabugMenu])
Yoshi.show()

Invocation Options

Yoshi can be invoked with a number of different options. The simplest way is to manually invoke using the show() function.

Yoshi.show()

In addition to the vanilla invocation option, Yoshi can also be invoked in response of 3 different options of motion or touch events.
If you want to enable all of those 3 following options you can simply pass the all option to the setupDebugMenu, although this option is already the default one.

Yoshi.setupDebugMenu([/* YoshiMenu items */], invocations: [.all])
/// Or simply
Yoshi.setupDebugMenu([/* YoshiMenu items */])

To specify which option you want exactly you just need to pass the ones you want to the setupDebugMenu function like this:

  • To invoke Yoshi in response to a shake-motion gesture, add the shakeMotionGesture option in the setupDebugMenu invocations parameter as follows.
Yoshi.setupDebugMenu([/* YoshiMenu items */], invocations: [.shakeMotionGesture])
  • To invoke Yoshi in in response to a multi-touch event, add the multiTouch option in the setupDebugMenu invocations parameter as follows.
Yoshi.setupDebugMenu([/* YoshiMenu items */], invocations: [.multiTouch])
  • Finally, to invoke Yoshi in response to a 3D touch event, add the forceTouch option in the setupDebugMenu invocations parameter as follows.
Yoshi.setupDebugMenu([/* YoshiMenu items */], invocations: [.forceTouch])

Contributing to Yoshi

To report a bug or enhancement request, feel free to file an issue under the respective heading.

If you wish to contribute to the project, fork this repo and submit a pull request. Code contributions should follow the standards specified in the Prolific Swift Style Guide.

License

prolific

Copyright (c) 2016 Prolific Interactive

Yoshi is maintained and sponsored by Prolific Interactive. It may be redistributed under the terms specified in the LICENSE file.

yoshi's People

Contributors

dannyvancura avatar haud avatar htinlinn avatar michaelcampbell avatar paulmiard avatar quentinr avatar yoyoyoseob avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.