Unverified Commit db11bf1d authored by dima.avdeev's avatar dima.avdeev Committed by GitHub

UIKit interop touches (#682)

parent f21b1970
......@@ -19,11 +19,16 @@ build configuration.
## Publishing
##### Publish to Maven local
##### Publish JVM target to Maven local
```
./gradlew publishToMavenLocal
```
##### Publish all targets to Maven Local
```
./gradlew publishToMavenLocal -Pskiko.native.enabled=true -Pskiko.wasm.enabled=true -Pskiko.android.enabled=true
```
##### Publish to `build/repo` directory
```
./gradlew publishToBuildRepo
......
......@@ -441,6 +441,14 @@ fun configureNativeTarget(os: OS, arch: Arch, target: KotlinNativeTarget) {
val allLibraries = skiaStaticLibraries(skiaDir, targetString) + bridgesLibrary
if (os == OS.IOS) {
target.compilations.getByName("main") {
val uikit by cinterops.creating {
defFile("src/iosMain/objc/ios.def")
packageName("org.jetbrains.skiko.objc")
}
}
}
val skiaBinDir = "$skiaDir/out/${buildType.id}-$targetString"
val linkerFlags = when (os) {
OS.MacOS -> mutableListOf("-linker-option", "-framework", "-linker-option", "Metal",
......
......@@ -20,3 +20,6 @@ dependencies.skia.android-arm64=m110-ad42464-1
org.gradle.jvmargs=-Xmx3G -XX:MaxMetaspaceSize=512m
kotlin.native.cacheKind.macosX64=none
kotlin.native.cacheKind.iosX64=none
# This line needs for maven publication with ObjC defFile. Should be removed after Kotlin 1.8.20
kotlin.mpp.enableCInteropCommonization=true
......@@ -7,6 +7,7 @@ import org.jetbrains.skiko.context.MetalContextHandler
import org.jetbrains.skiko.redrawer.MetalRedrawer
import platform.UIKit.*
import kotlin.system.getTimeNanos
import org.jetbrains.skia.*
actual open class SkiaLayer {
......
package org.jetbrains.skiko
import kotlinx.cinterop.*
import org.jetbrains.skia.Point
import org.jetbrains.skia.Rect
import platform.CoreGraphics.*
import platform.Foundation.*
......@@ -9,9 +10,14 @@ import platform.darwin.NSInteger
import kotlin.math.max
import kotlin.math.min
/*
TODO: remove org.jetbrains.skiko.objc.UIViewExtensionProtocol after Kotlin 1.8.20
https://youtrack.jetbrains.com/issue/KT-40426
*/
@Suppress("CONFLICTING_OVERLOADS")
@ExportObjCClass
class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol {
class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol,
org.jetbrains.skiko.objc.UIViewExtensionProtocol {
@OverrideInit
constructor(frame: CValue<CGRect>) : super(frame)
......@@ -19,6 +25,7 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol {
constructor(coder: NSCoder) : super(coder)
private var skiaLayer: SkiaLayer? = null
private lateinit var _pointInside: (Point, UIEvent?) -> Boolean
private var _inputDelegate: UITextInputDelegateProtocol? = null
private var _currentTextMenuActions: TextActions? = null
var currentKeyboardType: UIKeyboardType = UIKeyboardTypeDefault
......@@ -30,8 +37,13 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol {
var currentAutocapitalizationType: UITextAutocapitalizationType = UITextAutocapitalizationType.UITextAutocapitalizationTypeSentences
var currentAutocorrectionType: UITextAutocorrectionType = UITextAutocorrectionType.UITextAutocorrectionTypeYes
constructor(skiaLayer: SkiaLayer, frame: CValue<CGRect> = CGRectNull.readValue()) : super(frame) {
constructor(
skiaLayer: SkiaLayer,
frame: CValue<CGRect> = CGRectNull.readValue(),
pointInside: (Point, UIEvent?) -> Boolean = {_,_-> true }
) : super(frame) {
this.skiaLayer = skiaLayer
_pointInside = pointInside
}
/**
......@@ -157,6 +169,14 @@ class SkikoUIView : UIView, UIKeyInputProtocol, UITextInputProtocol {
super.pressesEnded(presses, withEvent)
}
/**
* https://developer.apple.com/documentation/uikit/uiview/1622533-point
*/
override fun pointInside(point: CValue<CGPoint>, withEvent: UIEvent?): Boolean {
val skiaPoint: Point = point.useContents { Point(x.toFloat(), y.toFloat()) }
return _pointInside(skiaPoint, withEvent)
}
override fun touchesBegan(touches: Set<*>, withEvent: UIEvent?) {
super.touchesBegan(touches, withEvent)
sendTouchEventToSkikoView(touches, SkikoTouchEventKind.STARTED)
......
package = org.jetbrains.skiko.objc
language = Objective-C
---
#import <Foundation/Foundation.h>
#import <UIKit/UIView.h>
// This protocol helps to override ObjC UIView extensions in Kotlin
@protocol UIViewExtension
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event;
@end
\ No newline at end of file
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