-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathSkipAndroidBridgeSamples.swift
More file actions
79 lines (64 loc) · 1.92 KB
/
Copy pathSkipAndroidBridgeSamples.swift
File metadata and controls
79 lines (64 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2024–2025 Skip
// SPDX-License-Identifier: LGPL-3.0-only WITH LGPL-3.0-linking-exception
import Foundation
import SkipBridge
import SkipAndroidBridge
import SwiftJNI
#if canImport(AndroidNative)
import AndroidNative
#endif
public let swiftStringConstant = "s"
public func getStringValue(_ string: String?) -> String? {
string
}
public func bundleClassName() -> String {
"\(Bundle.module)"
}
public func getAssetURL(named name: String) -> URL? {
Bundle.module.url(forResource: name, withExtension: nil)
}
public func getAssetContents(named name: String) throws -> Data? {
guard let url = getAssetURL(named: name) else { return nil }
return try Data(contentsOf: url)
}
public func userDefaultsClassName() -> String {
"\(UserDefaults.standard)"
}
public func getStringDefault(name: String) -> String? {
UserDefaults.standard.string(forKey: name)
}
public func setStringDefault(name: String, value: String?) {
UserDefaults.standard.set(value, forKey: name)
}
#if os(Linux)
// workaround for missing LocalizedStringResource on Linux
typealias LocalizedStringResource = AndroidLocalizedStringResource
#endif
public func localizedStringResourceLiteralKey() -> String {
let literal: LocalizedStringResource = "literal"
return literal.key
}
public func localizedStringResourceInterpolatedKey() -> String {
let value = 1
let interpolation: AndroidLocalizedStringResource = "interpolated \(value)!"
return interpolation.key
}
public func mainActorAsyncValue() async -> String {
await Task.detached {
await MainActorClass().mainActorValue()
}.value
}
public func nativeAndroidContextPackageName() throws -> String? {
#if os(Android)
return try AndroidContext.application.getPackageName()
#else
fatalError("cannot import AndroidNative")
#endif
}
@MainActor class MainActorClass {
init() {
}
func mainActorValue() -> String {
"MainActor!"
}
}