Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
skiko
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liuqiang
skiko
Commits
83394aa1
Unverified
Commit
83394aa1
authored
Jan 21, 2022
by
Roman Sedaikin
Committed by
GitHub
Jan 21, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support to show/hide screen keyboard. Refactored [SkikoUIViewController]. (#455)
parent
d3979724
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
45 deletions
+77
-45
App.ios.kt
.../src/iosMain/kotlin/org/jetbrains/skiko/sample/App.ios.kt
+7
-6
SkiaLayer.ios.kt
...o/src/iosMain/kotlin/org/jetbrains/skiko/SkiaLayer.ios.kt
+10
-0
SkikoViewController.kt
...iosMain/kotlin/org/jetbrains/skiko/SkikoViewController.kt
+60
-39
No files found.
samples/SkiaMultiplatformSample/src/iosMain/kotlin/org/jetbrains/skiko/sample/App.ios.kt
View file @
83394aa1
...
@@ -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.SkikoUIView
import
org.jetbrains.skiko.SkikoGestureEventKind
import
org.jetbrains.skiko.SkikoGestureEventKind
import
platform.UIKit.*
import
platform.UIKit.*
import
platform.Foundation.*
import
platform.Foundation.*
...
@@ -37,13 +38,13 @@ class SkikoAppDelegate : UIResponder, UIApplicationDelegateProtocol {
...
@@ -37,13 +38,13 @@ 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
(
SkikoGestureEventKind
.
values
()).
apply
{
window
!!
.
rootViewController
=
SkikoViewController
(
setAppFactory
{
layer
->
SkikoUIView
(
GenericSkikoView
(
layer
,
makeApp
(
layer
)).
also
{
SkiaLayer
(
SkikoGestureEventKind
.
values
()).
apply
{
layer
.
skikoView
=
it
skikoView
=
GenericSkikoView
(
this
,
makeApp
(
this
))
}
}
}
}
)
)
window
!!
.
makeKeyAndVisible
()
window
!!
.
makeKeyAndVisible
()
return
true
return
true
}
}
...
...
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkiaLayer.ios.kt
View file @
83394aa1
...
@@ -24,6 +24,16 @@ actual open class SkiaLayer {
...
@@ -24,6 +24,16 @@ actual open class SkiaLayer {
return
true
return
true
}
}
fun
showScreenKeyboard
()
{
view
?.
becomeFirstResponder
()
}
fun
hideScreenKeyboard
()
{
view
?.
resignFirstResponder
()
}
fun
isScreenKeyboardOpen
():
Boolean
{
return
if
(
view
==
null
)
false
else
view
!!
.
isFirstResponder
}
actual
var
renderApi
:
GraphicsApi
actual
var
renderApi
:
GraphicsApi
get
()
=
GraphicsApi
.
METAL
get
()
=
GraphicsApi
.
METAL
set
(
value
)
{
throw
UnsupportedOperationException
()
}
set
(
value
)
{
throw
UnsupportedOperationException
()
}
...
...
skiko/src/iosMain/kotlin/org/jetbrains/skiko/SkikoViewController.kt
View file @
83394aa1
package
org.jetbrains.skiko
package
org.jetbrains.skiko
import
kotlinx.cinterop.CValue
import
kotlinx.cinterop.ExportObjCClass
import
kotlinx.cinterop.ExportObjCClass
import
kotlinx.cinterop.useContents
import
kotlinx.cinterop.useContents
import
platform.CoreGraphics.CGRect
import
platform.CoreGraphics.CGRectMake
import
platform.CoreGraphics.CGRectMake
import
platform.Foundation.NSCoder
import
platform.Foundation.NSCoder
import
platform.UIKit.UIEvent
import
platform.UIKit.UIEvent
import
platform.UIKit.UITouch
import
platform.UIKit.UITouch
import
platform.UIKit.UIScreen
import
platform.UIKit.UIScreen
import
platform.UIKit.UIView
import
platform.UIKit.UIViewController
import
platform.UIKit.UIViewController
import
platform.UIKit.setFrame
import
platform.UIKit.setFrame
import
platform.UIKit.contentScaleFactor
import
platform.UIKit.contentScaleFactor
...
@@ -15,22 +18,63 @@ import platform.UIKit.UIPress
...
@@ -15,22 +18,63 @@ import platform.UIKit.UIPress
import
platform.UIKit.UIPressesEvent
import
platform.UIKit.UIPressesEvent
@ExportObjCClass
@ExportObjCClass
class
SkikoViewController
:
UIViewController
,
UIKeyInputProtocol
{
class
SkikoViewController
:
UIViewController
{
private
var
gestures
:
Array
<
SkikoGestureEventKind
>?
=
null
@OverrideInit
@OverrideInit
constructor
()
:
super
(
nibName
=
null
,
bundle
=
null
)
constructor
()
:
super
(
nibName
=
null
,
bundle
=
null
)
@OverrideInit
constructor
(
coder
:
NSCoder
)
:
super
(
coder
)
constructor
(
skikoUIView
:
SkikoUIView
)
:
this
()
{
this
.
skikoUIView
=
skikoUIView
}
private
var
skikoUIView
:
SkikoUIView
?
=
null
override
fun
loadView
()
{
if
(
skikoUIView
==
null
)
{
super
.
loadView
()
}
else
{
this
.
view
=
skikoUIView
!!
.
load
()
}
}
// viewDidUnload() is deprecated and not called.
override
fun
viewDidDisappear
(
animated
:
Boolean
)
{
skikoUIView
?.
detach
()
}
}
@ExportObjCClass
class
SkikoUIView
:
UIView
,
UIKeyInputProtocol
{
@OverrideInit
constructor
(
frame
:
CValue
<
CGRect
>)
:
super
(
frame
)
@OverrideInit
@OverrideInit
constructor
(
coder
:
NSCoder
)
:
super
(
coder
)
constructor
(
coder
:
NSCoder
)
:
super
(
coder
)
constructor
(
gestures
:
Array
<
SkikoGestureEventKind
>?
=
null
)
:
this
()
{
private
var
skiaLayer
:
SkiaLayer
?
=
null
this
.
gestures
=
gestures
constructor
(
skiaLayer
:
SkiaLayer
,
frame
:
CValue
<
CGRect
>
=
CGRectMake
(
0.0
,
0.0
,
1.0
,
1.0
))
:
super
(
frame
)
{
this
.
skiaLayer
=
skiaLayer
}
}
override
fun
canBecomeFirstResponder
()
=
true
fun
detach
()
=
skiaLayer
?.
detach
()
fun
load
():
SkikoUIView
{
val
(
width
,
height
)
=
UIScreen
.
mainScreen
.
bounds
.
useContents
{
this
.
size
.
width
to
this
.
size
.
height
}
setFrame
(
CGRectMake
(
0.0
,
0.0
,
width
,
height
))
contentScaleFactor
=
UIScreen
.
mainScreen
.
scale
skiaLayer
?.
attachTo
(
this
)
return
this
}
fun
showScreenKeyboard
()
=
becomeFirstResponder
()
fun
hideScreenKeyboard
()
=
resignFirstResponder
()
fun
isScreenKeyboardOpen
()
=
isFirstResponder
private
var
keyEvent
:
UIPress
?
=
null
var
keyEvent
:
UIPress
?
=
null
private
var
inputText
:
String
=
""
private
var
inputText
:
String
=
""
override
fun
hasText
():
Boolean
{
override
fun
hasText
():
Boolean
{
return
inputText
.
length
>
0
return
inputText
.
length
>
0
...
@@ -38,18 +82,20 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
...
@@ -38,18 +82,20 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
override
fun
insertText
(
theText
:
String
)
{
override
fun
insertText
(
theText
:
String
)
{
inputText
+=
theText
inputText
+=
theText
ski
koLayer
.
skikoView
?.
onInputEvent
(
toSkikoTypeEvent
(
theText
,
keyEvent
))
ski
aLayer
?
.
skikoView
?.
onInputEvent
(
toSkikoTypeEvent
(
theText
,
keyEvent
))
}
}
override
fun
deleteBackward
()
{
override
fun
deleteBackward
()
{
inputText
=
inputText
.
dropLast
(
1
)
inputText
=
inputText
.
dropLast
(
1
)
}
}
override
fun
canBecomeFirstResponder
()
=
true
override
fun
pressesBegan
(
presses
:
Set
<
*
>,
withEvent
:
UIPressesEvent
?)
{
override
fun
pressesBegan
(
presses
:
Set
<
*
>,
withEvent
:
UIPressesEvent
?)
{
if
(
withEvent
!=
null
)
{
if
(
withEvent
!=
null
)
{
for
(
press
in
withEvent
.
allPresses
)
{
for
(
press
in
withEvent
.
allPresses
)
{
keyEvent
=
press
as
UIPress
keyEvent
=
press
as
UIPress
ski
koLayer
.
skikoView
?.
onKeyboardEvent
(
ski
aLayer
?
.
skikoView
?.
onKeyboardEvent
(
toSkikoKeyboardEvent
(
press
,
SkikoKeyboardEventKind
.
DOWN
)
toSkikoKeyboardEvent
(
press
,
SkikoKeyboardEventKind
.
DOWN
)
)
)
}
}
...
@@ -61,7 +107,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
...
@@ -61,7 +107,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
if
(
withEvent
!=
null
)
{
if
(
withEvent
!=
null
)
{
for
(
press
in
withEvent
.
allPresses
)
{
for
(
press
in
withEvent
.
allPresses
)
{
keyEvent
=
press
as
UIPress
keyEvent
=
press
as
UIPress
ski
koLayer
.
skikoView
?.
onKeyboardEvent
(
ski
aLayer
?
.
skikoView
?.
onKeyboardEvent
(
toSkikoKeyboardEvent
(
press
,
SkikoKeyboardEventKind
.
UP
)
toSkikoKeyboardEvent
(
press
,
SkikoKeyboardEventKind
.
UP
)
)
)
}
}
...
@@ -80,7 +126,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
...
@@ -80,7 +126,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
STARTED
,
timestamp
,
event
)
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
STARTED
,
timestamp
,
event
)
)
)
}
}
ski
koLayer
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
ski
aLayer
?
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
}
}
override
fun
touchesEnded
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
override
fun
touchesEnded
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
...
@@ -94,7 +140,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
...
@@ -94,7 +140,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
ENDED
,
timestamp
,
event
)
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
ENDED
,
timestamp
,
event
)
)
)
}
}
ski
koLayer
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
ski
aLayer
?
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
}
}
override
fun
touchesMoved
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
override
fun
touchesMoved
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
...
@@ -108,7 +154,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
...
@@ -108,7 +154,7 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
MOVED
,
timestamp
,
event
)
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
MOVED
,
timestamp
,
event
)
)
)
}
}
ski
koLayer
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
ski
aLayer
?
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
}
}
override
fun
touchesCancelled
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
override
fun
touchesCancelled
(
touches
:
Set
<
*
>,
withEvent
:
UIEvent
?)
{
...
@@ -122,31 +168,6 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
...
@@ -122,31 +168,6 @@ class SkikoViewController : UIViewController, UIKeyInputProtocol {
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
CANCELLED
,
timestamp
,
event
)
SkikoTouchEvent
(
x
,
y
,
SkikoTouchEventKind
.
CANCELLED
,
timestamp
,
event
)
)
)
}
}
skikoLayer
.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
skiaLayer
?.
skikoView
?.
onTouchEvent
(
events
.
toTypedArray
())
}
internal
lateinit
var
appFactory
:
(
SkiaLayer
)
->
SkikoView
fun
setAppFactory
(
appFactory
:
(
SkiaLayer
)
->
SkikoView
)
{
this
.
appFactory
=
appFactory
}
private
lateinit
var
skikoLayer
:
SkiaLayer
override
fun
viewDidLoad
()
{
super
.
viewDidLoad
()
val
(
width
,
height
)
=
UIScreen
.
mainScreen
.
bounds
.
useContents
{
this
.
size
.
width
to
this
.
size
.
height
}
skikoLayer
=
SkiaLayer
(
gestures
).
apply
{
skikoView
=
appFactory
(
this
)
}
view
.
contentScaleFactor
=
UIScreen
.
mainScreen
.
scale
view
.
setFrame
(
CGRectMake
(
0.0
,
0.0
,
width
,
height
))
skikoLayer
.
attachTo
(
this
.
view
)
}
// viewDidUnload() is deprecated and not called.
override
fun
viewDidDisappear
(
animated
:
Boolean
)
{
skikoLayer
.
detach
()
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment