Remove react-native; rewrite main screen in (native) swift

This commit is contained in:
2019-03-25 20:39:44 -05:00
parent a546f6de73
commit 8544c5dc8a
148 changed files with 2007 additions and 8899 deletions

26
ios/Tests/Info.plist Normal file
View File

@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIAppFonts</key>
<array>
<string>fonts/FontAwesome.ttf</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -0,0 +1,69 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import XCTest
import UIKit
@testable import uhabits
class IosCanvasTest : XCTestCase {
func testDraw() {
UIGraphicsBeginImageContext(CGSize(width: 500, height: 400))
let canvas = IosCanvas(withBounds: CGRect(x: 0, y: 0, width: 500, height: 400))
canvas.setColor(color: Color(argb: 0x303030))
canvas.fillRect(x: 0.0, y: 0.0, width: 500.0, height: 400.0)
canvas.setColor(color: Color(argb: 0x606060))
canvas.setStrokeWidth(size: 25.0)
canvas.drawRect(x: 100.0, y: 100.0, width: 300.0, height: 200.0)
canvas.setColor(color: Color(argb: 0xFFFF00))
canvas.setStrokeWidth(size: 1.0)
canvas.fillCircle(centerX: 50.0, centerY: 50.0, radius: 30.0)
canvas.fillArc(centerX: 50.0, centerY: 150.0, radius: 30.0, startAngle: 90.0, swipeAngle: 135.0)
canvas.fillArc(centerX: 50.0, centerY: 250.0, radius: 30.0, startAngle: 90.0, swipeAngle: -135.0)
canvas.fillArc(centerX: 50.0, centerY: 350.0, radius: 30.0, startAngle: 45.0, swipeAngle: 90.0)
canvas.drawRect(x: 0.0, y: 0.0, width: 100.0, height: 100.0)
canvas.drawRect(x: 0.0, y: 100.0, width: 100.0, height: 100.0)
canvas.drawRect(x: 0.0, y: 200.0, width: 100.0, height: 100.0)
canvas.drawRect(x: 0.0, y: 300.0, width: 100.0, height: 100.0)
canvas.setColor(color: Color(argb: 0xFF0000))
canvas.setStrokeWidth(size: 2.0)
canvas.drawLine(x1: 0.0, y1: 0.0, x2: 500.0, y2: 400.0)
canvas.drawLine(x1: 500.0, y1: 0.0, x2: 0.0, y2: 400.0)
canvas.setTextSize(size: 50.0)
canvas.setColor(color: Color(argb: 0x00FF00))
canvas.drawText(text: "Test", x: 250.0, y: 200.0)
canvas.setFont(font: Font.bold)
canvas.drawText(text: "Test", x: 250.0, y: 100.0)
canvas.setFont(font: Font.fontAwesome)
canvas.drawText(text: FontAwesome.Companion().check, x: 250.0, y: 300.0)
let image = UIGraphicsGetImageFromCurrentImageContext()!
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
let filePath = paths.first?.appendingPathComponent("IosCanvasTest.png")
try! image.pngData()!.write(to: filePath!, options: .atomic)
UIGraphicsEndImageContext()
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import XCTest
import UIKit
@testable import uhabits
class IosDateTimeTest : XCTestCase {
func testPlusMinusDay() {
let today = LocalDate(year: 2019, month: 3, day: 25)
let calc = IosLocalDateCalculator()
let d1 = calc.minusDays(date: today, days: 28)
let d2 = calc.plusDays(date: today, days: 7)
let d3 = calc.plusDays(date: today, days: 42)
XCTAssert(d1.isEqual(LocalDate(year: 2019, month: 2, day: 25)))
XCTAssert(d2.isEqual(LocalDate(year: 2019, month: 4, day: 1)))
XCTAssert(d3.isEqual(LocalDate(year: 2019, month: 5, day: 6)))
}
}
class IosDateFormatterTest : XCTestCase {
func testShortMonthName() {
let fmt = IosLocalDateFormatter()
let d1 = LocalDate(year: 2019, month: 3, day: 25)
let d2 = LocalDate(year: 2019, month: 4, day: 4)
let d3 = LocalDate(year: 2019, month: 5, day: 12)
XCTAssertEqual(fmt.shortWeekdayName(date: d1), "Mon")
XCTAssertEqual(fmt.shortWeekdayName(date: d2), "Thu")
XCTAssertEqual(fmt.shortWeekdayName(date: d3), "Sun")
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import XCTest
@testable import uhabits
class IosFilesTest: XCTestCase {
func testResourceFiles() {
let fileOpener = IosFileOpener()
let file = fileOpener.openResourceFile(filename: "migrations/010.sql")
let lines = file.readLines()
XCTAssertEqual(lines[0], "delete from Score")
}
func testUserFiles() throws {
let fm = FileManager.default
let root = try fm.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false).path
let path = "\(root)/test.txt"
print(path)
fm.createFile(atPath: path, contents: "Hello world\nThis is line 2".data(using: .utf8), attributes: nil)
let fileOpener = IosFileOpener()
let file = fileOpener.openUserFile(filename: "test.txt")
XCTAssertTrue(file.exists())
file.delete()
XCTAssertFalse(file.exists())
}
}

View File

@@ -0,0 +1,73 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import XCTest
@testable import uhabits
class IosDatabaseTest: XCTestCase {
func testUsage() {
let databaseOpener = IosDatabaseOpener(withLog: StandardLog())
let fileOpener = IosFileOpener()
let dbFile = fileOpener.openUserFile(filename: "test.sqlite3")
if dbFile.exists() {
dbFile.delete()
}
let db = databaseOpener.open(file: dbFile)
var stmt = db.prepareStatement(sql: "drop table if exists demo")
stmt.step()
stmt.finalize()
stmt = db.prepareStatement(sql: "begin")
stmt.step()
stmt.finalize()
stmt = db.prepareStatement(sql: "create table if not exists demo(key int, value text)")
stmt.step()
stmt.finalize()
stmt = db.prepareStatement(sql: "insert into demo(key, value) values (?, ?)")
stmt.bindInt(index: 0, value: 42)
stmt.bindText(index: 1, value: "Hello World")
stmt.step()
stmt.finalize()
stmt = db.prepareStatement(sql: "select * from demo where key > ?")
stmt.bindInt(index: 0, value: 10)
var result = stmt.step()
XCTAssertEqual(result, StepResult.row)
XCTAssertEqual(stmt.getInt(index: 0), 42)
XCTAssertEqual(stmt.getText(index: 1), "Hello World")
result = stmt.step()
XCTAssertEqual(result, StepResult.done)
stmt.finalize()
stmt = db.prepareStatement(sql: "drop table demo")
stmt.step()
stmt.finalize()
stmt = db.prepareStatement(sql: "commit")
stmt.step()
stmt.finalize()
db.close()
dbFile.delete()
}
}