Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
402b2d57
Commit
402b2d57
authored
Oct 14, 2023
by
Evan W. Patton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more missing methods to iOS ListView
Change-Id: Ifb1edb80c6263f704a6aa1de52752fa469494349
parent
6424741c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
24 deletions
+130
-24
appinventor/components-ios/src/ListView.swift
appinventor/components-ios/src/ListView.swift
+59
-20
appinventor/components-ios/tests/Unit Tests/components/visible/ListViewTests.swift
...s/tests/Unit Tests/components/visible/ListViewTests.swift
+71
-4
No files found.
appinventor/components-ios/src/ListView.swift
View file @
402b2d57
...
...
@@ -90,11 +90,36 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
@objc
open
var
Elements
:
[
AnyObject
]
{
get
{
return
_elements
as
[
AnyObject
]
if
_listData
.
count
>
0
{
return
_listData
as
[
AnyObject
]
}
else
{
return
_elements
as
[
AnyObject
]
}
}
set
(
elements
)
{
_elements
=
elements
.
toStringArray
()
_automaticHeightConstraint
.
constant
=
_elements
.
isEmpty
?
kDefaultTableCellHeight
:
kDefaultTableCellHeight
*
CGFloat
(
_elements
.
count
)
_elements
=
[]
_listData
=
[]
guard
!
elements
.
isEmpty
else
{
_view
.
reloadData
()
return
}
if
elements
.
first
is
YailDictionary
{
for
item
in
elements
{
if
let
row
=
item
as?
YailDictionary
{
if
let
rowDict
=
row
as?
[
String
:
String
]
{
_listData
.
append
(
rowDict
)
}
}
else
if
let
row
=
item
as?
String
{
_listData
.
append
([
"Text1"
:
row
,
"Text2"
:
""
,
"Image"
:
""
])
}
else
{
// Hmm...
}
}
}
else
{
_elements
=
elements
.
toStringArray
()
}
let
rows
=
max
(
_elements
.
count
,
_listData
.
count
)
_automaticHeightConstraint
.
constant
=
rows
==
0
?
kDefaultTableCellHeight
:
kDefaultTableCellHeight
*
CGFloat
(
rows
)
if
let
searchBar
=
_view
.
tableHeaderView
as?
UISearchBar
{
self
.
searchBar
(
searchBar
,
textDidChange
:
searchBar
.
text
??
""
)
}
else
{
...
...
@@ -104,14 +129,13 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
}
@objc
open
var
FontTypeface
:
String
{
get
{
return
_fontTypeface
}
set
(
fontTypeface
)
{
_fontTypeface
=
fontTypeface
print
(
_fontTypeface
)
_view
.
reloadData
()
}
get
{
return
_fontTypeface
}
set
(
fontTypeface
)
{
_fontTypeface
=
fontTypeface
_view
.
reloadData
()
}
}
@objc
open
var
FontTypefaceDetail
:
String
{
...
...
@@ -120,7 +144,6 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
}
set
(
FontTypefaceDetail
)
{
_fontTypefaceDetail
=
FontTypefaceDetail
print
(
_fontTypeface
)
_view
.
reloadData
()
}
}
...
...
@@ -138,10 +161,6 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
}
set
(
jsonString
)
{
do
{
print
(
"JSON string:
\(
jsonString
)
"
)
let
jsonObject
=
try
getObjectFromJson
(
jsonString
)
print
(
"JSON object:
\(
jsonObject
)
"
)
if
let
dictionaries
=
try
getObjectFromJson
(
jsonString
)
as?
[[
String
:
Any
]]
{
_listData
=
dictionaries
.
compactMap
{
dictionary
in
var
item
:
[
String
:
String
]
=
[:]
...
...
@@ -180,7 +199,6 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
}
set
(
listViewLayoutMode
)
{
_listViewLayoutMode
=
listViewLayoutMode
print
(
"ListViewLayout
\(
ListViewLayout
)
"
)
_view
.
reloadData
()
}
}
...
...
@@ -191,7 +209,6 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
}
set
(
orientation
)
{
_orientation
=
orientation
print
(
"Orientation
\(
Orientation
)
"
)
_view
.
reloadData
()
}
}
...
...
@@ -211,13 +228,11 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
}
else
if
let
index
=
_listData
.
firstIndex
(
where
:
{
$0
[
"Text1"
]
==
selection
})
{
_selectionIndex
=
Int32
(
index
)
+
1
_selection
=
selection
print
(
"selection index
\(
_selection
)
"
)
_view
.
selectRow
(
at
:
IndexPath
(
item
:
index
,
section
:
0
),
animated
:
true
,
scrollPosition
:
.
none
)
}
else
{
_selectionIndex
=
0
_selection
=
""
}
print
(
"Selection set:
\(
_selection
)
"
)
}
}
...
...
@@ -334,6 +349,30 @@ open class ListView: ViewComponent, AbstractMethodsForViewComponent,
// MARK: Methods
@objc
open
func
CreateElement
(
_
mainText
:
String
,
_
detailText
:
String
,
_
imageName
:
String
)
->
YailDictionary
{
return
[
"Text1"
:
mainText
,
"Text2"
:
detailText
,
"Image"
:
imageName
]
as
YailDictionary
}
@objc
open
func
GetDetailText
(
_
listElement
:
YailDictionary
)
->
String
{
return
listElement
[
"Text2"
]
as?
String
??
""
}
@objc
open
func
GetImageName
(
_
listElement
:
YailDictionary
)
->
String
{
return
listElement
[
"Image"
]
as?
String
??
""
}
@objc
open
func
GetMainText
(
_
listElement
:
YailDictionary
)
->
String
{
return
listElement
[
"Text1"
]
as?
String
??
""
}
@objc
open
func
Refresh
()
{
_view
.
reloadData
()
}
@objc
open
func
RemoveItemAtIndex
(
_
index
:
Int32
)
{
if
index
<
1
||
index
>
max
(
_listData
.
count
,
_elements
.
count
)
{
_container
?
.
form
?
.
dispatchErrorOccurredEvent
(
self
,
"RemoveItemAtIndex"
,
...
...
appinventor/components-ios/tests/Unit Tests/components/visible/ListViewTests.swift
View file @
402b2d57
...
...
@@ -6,14 +6,14 @@
import
XCTest
@testable
import
AIComponentKit
class
ListViewTests
:
XC
TestCase
{
class
ListViewTests
:
AppInventor
TestCase
{
var
testForm
:
ReplForm
!
var
testList
:
ListView
!
override
func
setUp
()
{
testForm
=
ReplForm
()
testList
=
ListView
(
testForm
)
super
.
setUp
()
testList
=
ListView
(
form
)
XCTAssertTrue
(
addComponent
(
testList
,
named
:
"ListView1"
))
}
func
testSelectionIndex
()
{
...
...
@@ -29,4 +29,71 @@ class ListViewTests: XCTestCase {
XCTAssertEqual
(
"banana"
,
testList
.
Selection
)
}
func
testCreateElement
()
{
testList
.
Elements
=
[
testList
.
CreateElement
(
"MainText"
,
"DetailText"
,
"Image"
)]
XCTAssertEqual
(
1
,
testList
.
Elements
.
count
)
XCTAssertEqual
(
"MainText"
,
testList
.
GetMainText
(
YailDictionary
(
dictionary
:
testList
.
Elements
[
0
]
as!
Dictionary
)))
XCTAssertEqual
(
"DetailText"
,
testList
.
GetDetailText
(
YailDictionary
(
dictionary
:
testList
.
Elements
[
0
]
as!
Dictionary
)))
XCTAssertEqual
(
"Image"
,
testList
.
GetImageName
(
YailDictionary
(
dictionary
:
testList
.
Elements
[
0
]
as!
Dictionary
)))
}
func
testBackgroundColor
()
{
testList
.
BackgroundColor
=
Color
.
blue
.
int32
testList
.
Elements
=
[
"Test"
]
as
[
AnyObject
]
let
view
=
testList
.
view
as!
UITableView
var
cell
=
testList
.
tableView
(
view
,
cellForRowAt
:
IndexPath
(
row
:
0
,
section
:
0
))
XCTAssertNotNil
(
cell
)
XCTAssertEqual
(
Color
.
blue
.
uiColor
,
cell
.
backgroundColor
)
// Change back to the default (black)
testList
.
BackgroundColor
=
Color
.
default
.
int32
XCTAssertEqual
(
Color
.
black
.
int32
,
testList
.
BackgroundColor
)
cell
=
testList
.
tableView
(
view
,
cellForRowAt
:
IndexPath
(
row
:
0
,
section
:
0
))
XCTAssertNotNil
(
cell
)
XCTAssertEqual
(
Color
.
black
.
uiColor
,
cell
.
backgroundColor
)
}
func
testMixedElements
()
{
testList
.
Elements
=
[
testList
.
CreateElement
(
"MainText"
,
""
,
""
),
"Plain String"
]
as
[
AnyObject
]
XCTAssertEqual
(
2
,
testList
.
Elements
.
count
)
// The second element should be promoted to a dictionary
XCTAssertNotNil
(
testList
.
Elements
[
1
]
as?
Dictionary
<
String
,
String
>
)
}
func
testFontTypeface
()
{
testList
.
FontTypeface
=
"2"
testList
.
Elements
=
[
"Test"
]
as
[
AnyObject
]
testList
.
Refresh
()
let
view
=
testList
.
view
as!
UITableView
let
cell
=
testList
.
tableView
(
view
,
cellForRowAt
:
IndexPath
(
row
:
0
,
section
:
0
))
XCTAssertNotNil
(
cell
)
XCTAssertEqual
(
"Times New Roman"
,
cell
.
textLabel
?
.
font
.
familyName
)
}
func
testListData
()
{
testList
.
ListData
=
"[{
\"
Text1
\"
:
\"
apple
\"
,
\"
Text2
\"
:
\"
2.99
\"
,
\"
Image
\"
:
\"
apple.jpg
\"
}]"
XCTAssertEqual
(
1
,
testList
.
Elements
.
count
)
XCTAssertEqual
([[
"Text1"
:
"apple"
,
"Text2"
:
"2.99"
,
"Image"
:
"apple.jpg"
]],
testList
.
Elements
as?
[[
String
:
String
]])
}
func
testBadListData
()
{
testList
.
ListData
=
"this is not json"
XCTAssertEqual
(
0
,
testList
.
Elements
.
count
)
}
// MARK: Events
func
testAfterPicking
()
{
expectToReceiveEvent
(
on
:
testList
,
named
:
"AfterPicking"
)
{
[
self
]
arguments
in
XCTAssertEqual
(
2
,
testList
.
SelectionIndex
)
XCTAssertEqual
(
"banana"
,
testList
.
Selection
)
}
testList
.
Elements
=
[
"apple"
,
"banana"
,
"cantaloupe"
]
as
[
AnyObject
]
testList
.
Refresh
()
let
view
=
testList
.
view
as!
UITableView
testList
.
tableView
(
view
,
didSelectRowAt
:
IndexPath
(
row
:
1
,
section
:
0
))
verify
()
}
}
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