GithubHelp home page GithubHelp logo

furkanvijapura / keyboardkit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from keyboardkit/keyboardkit

0.0 1.0 0.0 2.09 MB

KeyboardKit is a Swift library for creating iOS keyboard extension apps.

License: MIT License

Ruby 2.50% Swift 96.70% Objective-C 0.80%

keyboardkit's Introduction

Current Version Build Status MIT License Twitter: @danielsaidi

Welcome to KeyboardKit - a Swift library that helps you create custom keyboard extensions for iOS. It supports a wide range of keyboard actions, which lets you create keyboards with text inputs, emojis, system actions and custom images.

Installation

CocoaPods

Add this to your Podfile, run pod install then remember to use the generated workspace afterwards:

pod 'KeyboardKit'

Carthage

Add this to your Cartfile, run carthage update then add the framework to the app from Carthage/Build:

github "danielsaidi/KeyboardKit"

Manual installation

To add KeyboardKit to your app without using Carthage or CocoaPods, clone this repository and place it anywhere within your project folder. After that, add the KeyboardKit.xcodeproj project to your project, select your app target then add the KeyboardKit framework as an embedded binary (under General) and a target dependency (under Build Phases).

Features

Keyboard actions

KeyboardKit comes with the following keyboard actions:

  • none- used as empty placeholders
  • backspace - sends a backspace to the text proxy
  • character - a plain text character, system emoji or symbol
  • image - custom images with a description, keyboard image and original image
  • newLine - inserts a new line into the text proxy
  • nextKeyboard - changes keyboard on tap and show the picker on long press
  • shift - can be used to change the char casing of a keyboard
  • space - inserts an empty space into the text proxy

KeyboardKit will handle all actions except image automatically with optional overrides, if you want to customize the handling of one or several actions.

UIInputViewController subclasses

KeyboardKit lets you create custom keyboard extensions in seveal ways, instead of inheriting UIInputViewController:

  • Inherit KeyboardInputViewController and use xibs
  • Inherit KeyboardInputViewController and use the Keyboard class
  • Inherit GridKeyboardInputViewController to create a grid-based keyboard
  • Inherit CollectionKeyboardInputViewController to create a collection-based keyboard

The GridKeyboardInputViewController option is currently most powerful, but the other options will give you basic functionality as well.

When you have your input view controller all setup, you just have to handle taps and long presses by overriding handleTap(on:) and handleLongPress(on:). Most options will be automatically handled (with optional overrides), but images must be manually handled, since there's no way to handle images natively in input vcs.

KeyboardKit also provides you with a setHeight function, that lets you set a custom height to your keyboard extension.

xib-based keyboards

When you use xibs, inherit KeyboardInputViewController instead of the system UIInputViewController class. Then, you can just bind the buttons in your xib to the desired keyboard actions.

Keyboard-based keyboards

When you use the Keyboard class, inherit KeyboardInputViewController instead of the system UIInputViewController class. Then, you must layout your keyboard manually with code. This is the least powerful option, but I will not judge.

GridKeyboardInputViewController-based keyboards

If you inherit GridKeyboardInputViewController, you will get a collection view that distributes the actions in an even-sized grid. It will automatically enable horizontal scrolling and display a page control if there are more buttons than fits the screen. It also lets you setup left and right system buttons, which are displayed below the collection view.

You setup a GridKeyboardInputViewController by providing it with a keyboard, a height (excluding a possible system row), how may button rows to display on each page, and how many buttons to have on each row. This setup can be changed at any time, e.g. when the device is rotated.

GridKeyboardInputViewController will automatically display a system button row below the keyboard, if any of these criterias are met:

  • leftSystemButtons contains at least one button
  • rightSystemButtons contains at least one button
  • there are more keyboard actions than fits one screen (displays a page control)
  • the device does not display a system keyboard switcher (which iPhone X does)

The system button area height is added to the total height. By default, it is as tall as the keyboard item size.

Need more features?

So far, GridKeyboardInputViewController is the only class I use in my own apps, which means that it has much functionality that the others lack. This means that you get much for free when you inherit it, but it also forces you to go with the grid layout, which may not be for everyone.

If you use KeyboardKit and need these features elsewhere, we must extract them out of GridKeyboardInputViewController.

Keyboards

In KeyboardKit, a Keyboard is basically just a list of KeyboardActions. It is presented as is specified by the selected input view controller base class. A xib-based approach is fully customizable, while the grid-based approach will use a collection view with even-sized cells.

Keyboard alerts

Since keyboard extensions cannot display UIAlertController alerts, KeyboardKit comes with custom alerters that can display alerts ontop of the keyboard.

Extensions

KeyboardKit comes with a bunch of extensions that simplifies working with this kind of keyboard extensions. Most are internal and only used within the library, but some are public and can e.g. be used to handle, save and export images. Have a look at the example app for more information.

Example Application

The easiest way to learn how to use KeyboardKit is to open the example app and have a look at how it is implemented. It uses a couple of regular strings, a few emojis, some images and a couple of system buttons.

The app uses a built-in GridKeyboardInputViewController base class, which uses a collection view to distribute the keyboard buttons evenly in a grid. It can be used in any keyboard extension. It uses custom cells, which means that it can be entirely tailored to your needs.

IMPORTANT - How to adding KeyboardKit to your extension

When you create your own keyboard extension and want to use KeyboardKit to get up and running, you have to do the following:

  • Create a new Custom Keyboard Extension target
  • In the hosting app: Add KeyboardKit to Embedded Binaries
  • In the extension: Add KeyboardKit to Linked Frameworks And Binaries
  • Enable full access in the Info.plist, if your keyboard needs it

Contact me

I hope you like this library. Feel free to reach out if you have questions or if you want to contribute in any way:

License

KeyboardKit is available under the MIT license. See LICENSE file for more info.

keyboardkit's People

Contributors

danielsaidi avatar

Watchers

James Cloos 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.