Unverified Commit d3979724 authored by Roman Sedaikin's avatar Roman Sedaikin Committed by GitHub

Added feature to define particular gestures to be used in UIView. (#454)

parent 084c17ad
...@@ -6,6 +6,7 @@ import org.jetbrains.skiko.GenericSkikoView ...@@ -6,6 +6,7 @@ import org.jetbrains.skiko.GenericSkikoView
import org.jetbrains.skiko.SkiaLayer import org.jetbrains.skiko.SkiaLayer
import org.jetbrains.skiko.SkikoView import org.jetbrains.skiko.SkikoView
import org.jetbrains.skiko.SkikoViewController import org.jetbrains.skiko.SkikoViewController
import org.jetbrains.skiko.SkikoGestureEventKind
import platform.UIKit.* import platform.UIKit.*
import platform.Foundation.* import platform.Foundation.*
...@@ -36,7 +37,7 @@ class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol { ...@@ -36,7 +37,7 @@ class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean { override fun application(application: UIApplication, didFinishLaunchingWithOptions: Map<Any?, *>?): Boolean {
window = UIWindow(frame = UIScreen.mainScreen.bounds) window = UIWindow(frame = UIScreen.mainScreen.bounds)
window!!.rootViewController = SkikoViewController().apply { window!!.rootViewController = SkikoViewController(SkikoGestureEventKind.values()).apply {
setAppFactory { layer -> setAppFactory { layer ->
GenericSkikoView(layer, makeApp(layer)).also { GenericSkikoView(layer, makeApp(layer)).also {
layer.skikoView = it layer.skikoView = it
......
...@@ -14,6 +14,12 @@ import platform.darwin.NSObject ...@@ -14,6 +14,12 @@ import platform.darwin.NSObject
import kotlin.system.getTimeNanos import kotlin.system.getTimeNanos
actual open class SkiaLayer { actual open class SkiaLayer {
private val gestures: Array<SkikoGestureEventKind>?
constructor(gestures: Array<SkikoGestureEventKind>? = null) {
this.gestures = gestures
}
fun isShowing(): Boolean { fun isShowing(): Boolean {
return true return true
} }
...@@ -142,15 +148,29 @@ actual open class SkiaLayer { ...@@ -142,15 +148,29 @@ actual open class SkiaLayer {
) )
) )
} }
} }
if (!gestures.isNullOrEmpty()) {
// We have ':' in selector to take care of function argument. // We have ':' in selector to take care of function argument.
if (gestures.contains(SkikoGestureEventKind.TAP)) {
view.addGestureRecognizer(UITapGestureRecognizer(controller, NSSelectorFromString("onTap:"))) view.addGestureRecognizer(UITapGestureRecognizer(controller, NSSelectorFromString("onTap:")))
}
if (gestures.contains(SkikoGestureEventKind.LONGPRESS)) {
view.addGestureRecognizer(UILongPressGestureRecognizer(controller, NSSelectorFromString("onLongPress:"))) view.addGestureRecognizer(UILongPressGestureRecognizer(controller, NSSelectorFromString("onLongPress:")))
}
if (gestures.contains(SkikoGestureEventKind.PINCH)) {
view.addGestureRecognizer(UIPinchGestureRecognizer(controller, NSSelectorFromString("onPinch:"))) view.addGestureRecognizer(UIPinchGestureRecognizer(controller, NSSelectorFromString("onPinch:")))
}
if (gestures.contains(SkikoGestureEventKind.ROTATION)) {
view.addGestureRecognizer(UIRotationGestureRecognizer(controller, NSSelectorFromString("onRotation:"))) view.addGestureRecognizer(UIRotationGestureRecognizer(controller, NSSelectorFromString("onRotation:")))
}
if (gestures.contains(SkikoGestureEventKind.SWIPE)) {
view.addGestureRecognizer(UISwipeGestureRecognizer(controller, NSSelectorFromString("onSwipe:"))) view.addGestureRecognizer(UISwipeGestureRecognizer(controller, NSSelectorFromString("onSwipe:")))
}
if (gestures.contains(SkikoGestureEventKind.PAN)) {
view.addGestureRecognizer(UIPanGestureRecognizer(controller, NSSelectorFromString("onPan:"))) view.addGestureRecognizer(UIPanGestureRecognizer(controller, NSSelectorFromString("onPan:")))
}
}
// TODO: maybe add observer for view.viewDidDisappear() to detach us? // TODO: maybe add observer for view.viewDidDisappear() to detach us?
redrawer = MetalRedrawer(this).apply { redrawer = MetalRedrawer(this).apply {
needRedraw() needRedraw()
......
...@@ -16,12 +16,18 @@ import platform.UIKit.UIPressesEvent ...@@ -16,12 +16,18 @@ import platform.UIKit.UIPressesEvent
@ExportObjCClass @ExportObjCClass
class SkikoViewController : UIViewController, UIKeyInputProtocol { class SkikoViewController : UIViewController, UIKeyInputProtocol {
private var gestures: Array<SkikoGestureEventKind>? = null
@OverrideInit @OverrideInit
constructor() : super(nibName = null, bundle = null) constructor() : super(nibName = null, bundle = null)
@OverrideInit @OverrideInit
constructor(coder: NSCoder) : super(coder) constructor(coder: NSCoder) : super(coder)
constructor(gestures: Array<SkikoGestureEventKind>? = null) : this() {
this.gestures = gestures
}
override fun canBecomeFirstResponder() = true override fun canBecomeFirstResponder() = true
private var keyEvent: UIPress? = null private var keyEvent: UIPress? = null
...@@ -131,7 +137,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol { ...@@ -131,7 +137,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
val (width, height) = UIScreen.mainScreen.bounds.useContents { val (width, height) = UIScreen.mainScreen.bounds.useContents {
this.size.width to this.size.height this.size.width to this.size.height
} }
skikoLayer = SkiaLayer().apply { skikoLayer = SkiaLayer(gestures).apply {
skikoView = appFactory(this) skikoView = appFactory(this)
} }
view.contentScaleFactor = UIScreen.mainScreen.scale view.contentScaleFactor = UIScreen.mainScreen.scale
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment