Unverified Commit 35f6a800 authored by Amelia Zhang's avatar Amelia Zhang Committed by GitHub

Implement DefaultFileScope enum for iOS (#2943)

parent d2f346cc
......@@ -168,6 +168,8 @@
22843757284F89DF00EC3133 /* AssetFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22843756284F89DF00EC3133 /* AssetFetcher.swift */; };
46E77D8E29DD6894002CCDFB /* ShowAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46E77D8D29DD6894002CCDFB /* ShowAlert.swift */; };
5132E481C0B949ECDE06AE78 /* Pods_AIComponentKit_AIComponentKitTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4FD2633D7266389EB43FF45F /* Pods_AIComponentKit_AIComponentKitTests.framework */; };
681D59052A84138A007B5DB5 /* FileScope.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681D59042A84138A007B5DB5 /* FileScope.swift */; };
681D59072A84139E007B5DB5 /* OptionList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 681D59062A84139E007B5DB5 /* OptionList.swift */; };
703C389B22B059C6000EA56A /* UIBezierPath+EllipticalArc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 703C389A22B059C6000EA56A /* UIBezierPath+EllipticalArc.swift */; };
C41392922280708000DBA8C6 /* Switch.swift in Sources */ = {isa = PBXBuildFile; fileRef = C41392912280708000DBA8C6 /* Switch.swift */; };
C4D38CC7230DCDF300D09FE3 /* VerticalScrollArrangement.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D38CC6230DCDF300D09FE3 /* VerticalScrollArrangement.swift */; };
......@@ -409,6 +411,8 @@
46E77D8D29DD6894002CCDFB /* ShowAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShowAlert.swift; sourceTree = "<group>"; };
4FD2633D7266389EB43FF45F /* Pods_AIComponentKit_AIComponentKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AIComponentKit_AIComponentKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
58E89B4AF39EEFF895CBBDD1 /* Pods-AIComponentKit-AIComponentKitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIComponentKit-AIComponentKitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AIComponentKit-AIComponentKitTests/Pods-AIComponentKit-AIComponentKitTests.release.xcconfig"; sourceTree = "<group>"; };
681D59042A84138A007B5DB5 /* FileScope.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileScope.swift; sourceTree = "<group>"; };
681D59062A84139E007B5DB5 /* OptionList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OptionList.swift; sourceTree = "<group>"; };
685FE23350C9E159CA508795 /* Pods-AIComponentKitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIComponentKitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AIComponentKitTests/Pods-AIComponentKitTests.debug.xcconfig"; sourceTree = "<group>"; };
703C389A22B059C6000EA56A /* UIBezierPath+EllipticalArc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBezierPath+EllipticalArc.swift"; sourceTree = "<group>"; };
99F760E80DBC747A467E4900 /* Pods-AIComponentKit.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AIComponentKit.release.xcconfig"; path = "Pods/Target Support Files/Pods-AIComponentKit/Pods-AIComponentKit.release.xcconfig"; sourceTree = "<group>"; };
......@@ -778,6 +782,7 @@
06E59EA21D92C66B00C42804 /* components */ = {
isa = PBXGroup;
children = (
681D59032A84137D007B5DB5 /* common */,
06E59EAD1D92C92300C42804 /* interfaces */,
06E59EAC1D92C91D00C42804 /* nonvisible */,
06E59EAB1D92C91800C42804 /* visible */,
......@@ -924,6 +929,15 @@
path = util;
sourceTree = "<group>";
};
681D59032A84137D007B5DB5 /* common */ = {
isa = PBXGroup;
children = (
681D59042A84138A007B5DB5 /* FileScope.swift */,
681D59062A84139E007B5DB5 /* OptionList.swift */,
);
name = common;
sourceTree = "<group>";
};
7474807A747CFE996FC4893A /* Pods */ = {
isa = PBXGroup;
children = (
......@@ -1273,6 +1287,7 @@
082778F720112FE300ACC99A /* ImagePicker.swift in Sources */,
068E0EAF1DC251090086FFDA /* ActivityStarter.swift in Sources */,
DE999D34201272DA0023DA47 /* VideoPlayer.swift in Sources */,
681D59072A84139E007B5DB5 /* OptionList.swift in Sources */,
06B216061DB95155000B3366 /* Image.swift in Sources */,
06E59EAF1D92D14F00C42804 /* Sound.swift in Sources */,
088CAFD020DABB2E002B1B67 /* Ball.swift in Sources */,
......@@ -1360,6 +1375,7 @@
062217F02A37767F00B89562 /* image.pb.swift in Sources */,
DE91AB931F93FF8F00AB742A /* PhoneNumberPicker.swift in Sources */,
DE84293420D3FC6A00094BCB /* GeometryUtil.swift in Sources */,
681D59052A84138A007B5DB5 /* FileScope.swift in Sources */,
068E0EB11DC251240086FFDA /* Clock.swift in Sources */,
0644F6C01F37CAD800642E4D /* Player.swift in Sources */,
06B216081DB954A5000B3366 /* ColorUtil.swift in Sources */,
......
// -*- mode: swift; swift-mode:basic-offset: 2; -*-
// Copyright 2023 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
import Foundation
@objc public class FileScope: NSObject, OptionList {
@objc public static let App = FileScope("App")
@objc public static let Asset = FileScope("Asset")
@objc public static let Cache = FileScope("Cache")
@objc public static let Legacy = FileScope("Legacy")
@objc public static let Private = FileScope("Private")
@objc public static let Shared = FileScope("Shared")
private static let LOOKUP: [String:FileScope] = [
"App": FileScope.App,
"Asset": FileScope.Asset,
"Cache": FileScope.Cache,
"Legacy": FileScope.Legacy,
"Private": FileScope.Private,
"Shared": FileScope.Shared
]
let label: NSString
@objc private init(_ label: NSString) {
self.label = label
}
@objc class func fromUnderlyingValue(_ scope: String) -> FileScope? {
return LOOKUP[scope]
}
@objc public func toUnderlyingValue() -> AnyObject {
return label
}
}
......@@ -25,6 +25,7 @@ let kMinimumToastWait = 10.0
fileprivate var _aboutScreen: String?
fileprivate var _appName: String?
fileprivate var _accentColor: Int32 = Int32(bitPattern: 0xFFFF4081)
fileprivate var _defaultFileScope = FileScope.App
fileprivate var _primaryColor: Int32 = Int32(bitPattern: 0xFF3F51B5)
fileprivate var _primaryColorDark: Int32 = Int32(bitPattern: 0xFF303F9F)
fileprivate var _scrollable = false
......@@ -500,7 +501,16 @@ let kMinimumToastWait = 10.0
}
}
@objc open var DefaultFileScope: FileScope {
get {
return _defaultFileScope
}
set {
_defaultFileScope = newValue
}
}
@objc open var DeviceDensity: Float {
get {
return deviceDensity
......
// -*- mode: swift; swift-mode:basic-offset: 2; -*-
// Copyright 2023 MIT, All rights reserved
// Released under the Apache License, Version 2.0
// http://www.apache.org/licenses/LICENSE-2.0
import Foundation
@objc public protocol OptionList {
func toUnderlyingValue() -> AnyObject
}
......@@ -315,8 +315,21 @@
((equal? type 'key) (coerce-to-key arg))
((equal? type 'dictionary) (coerce-to-dictionary arg))
((equal? type 'any) arg)
((enum-type? type) (coerce-to-enum arg type))
(else (coerce-to-component-of-type arg type)))))
(define (enum-type? type)
(string-contains (symbol->string type) "Enum"))
(define (enum? arg)
(instance? arg AIComponentKit.OptionList))
(define (coerce-to-enum arg type)
(if (and (enum? arg)
(apply yail:isa (list arg (string->symbol (string-replace-all (string-replace-all (symbol->string type) "Enum" "") "com.google.appinventor.components.common" "AIComponentKit")))))
arg
(or (yail:invoke (string->symbol (string-replace-all (string-replace-all (symbol->string type) "Enum" "") "com.google.appinventor.components.common" "AIComponentKit")) 'fromUnderlyingValue arg) *non-coercible-value*)))
(define (coerce-to-text arg)
(if (eq? arg *the-null-value*)
*non-coercible-value*
......
......@@ -339,4 +339,20 @@ class RuntimeTests: XCTestCase {
XCTAssertNil(interpreter.exception)
XCTAssertEqual("{}", label.Text)
}
func testEnum() throws {
let interpreter = try getInterpreterForTesting()
XCTAssertEqual("#t", interpreter.evalForm("(enum? (static-field AIComponentKit.FileScope 'Shared))"))
XCTAssertNil(interpreter.exception)
}
func testEnums() throws {
let interpreter = try getInterpreterForTesting()
let form = Form()
form.environment["Screen1"] = form
interpreter.setCurrentForm(form)
interpreter.evalForm("(set-and-coerce-property! 'Screen1 'DefaultFileScope \"Shared\" 'com.google.appinventor.components.common.FileScopeEnum)")
XCTAssertNil(interpreter.exception)
XCTAssertEqual(FileScope.Shared, form.DefaultFileScope)
}
}
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