-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from angelolloqui/feature/UIKitTransform
Implemented basic UIKit -> Android widget transform plugins
- Loading branch information
Showing
8 changed files
with
103 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
class ViewController: UIViewController { | ||
@BindView() lateinit var view: View | ||
@BindView() lateinit var label: TextView | ||
@BindView() lateinit var textField: EditText | ||
@BindView() lateinit var imageView: ImageView | ||
@BindView() lateinit var button: Button | ||
@BindView() lateinit var tableView: RecyclerView | ||
@BindView() lateinit var stackView: LinearLayout | ||
@BindView() lateinit var scrollView: ScrollView | ||
@BindView() lateinit var aSwitch: Switch | ||
|
||
fun method(label: TextView) : View { | ||
val view = View() | ||
view.addSubview(view) | ||
return view | ||
} | ||
|
||
@OnClick() fun onTap() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
class ViewController: UIViewController { | ||
@IBOutlet weak var view: UIView! | ||
@IBOutlet weak var label: UILabel! | ||
@IBOutlet weak var textField: UITextField! | ||
@IBOutlet weak var imageView: UIImageView! | ||
@IBOutlet weak var button: UIButton! | ||
@IBOutlet weak var tableView: UITableView! | ||
@IBOutlet weak var stackView: UIStackView! | ||
@IBOutlet weak var scrollView: UIScrollView! | ||
@IBOutlet weak var aSwitch: UISwitch! | ||
|
||
func method(label: UILabel) -> UIView { | ||
let view = UIView() | ||
view.addSubview(view) | ||
return view | ||
} | ||
|
||
@IBAction func onTap() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
Sources/SwiftKotlinFramework/plugins/UIKitTransformPlugin.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// UIKitTransformPlugin.swift | ||
// SwiftKotlinFramework | ||
// | ||
// Created by Angel Luis Garcia on 17/05/2020. | ||
// | ||
|
||
import Foundation | ||
import Transform | ||
import AST | ||
|
||
public class UIKitTransformPlugin: TokenTransformPlugin { | ||
public var name: String { | ||
return "UIKit transformations" | ||
} | ||
|
||
public var description: String { | ||
return "Transforms classes like UIView, UILabel,... to their Android counterpart" | ||
} | ||
|
||
public init() {} | ||
|
||
public func transform(tokens: [Token], topDeclaration: TopLevelDeclaration) throws -> [Token] { | ||
var newTokens = [Token]() | ||
|
||
for token in tokens { | ||
if token.kind == .identifier, let mapping = classMappings[token.value], let node = token.node { | ||
newTokens.append(node.newToken(.identifier, mapping)) | ||
} else { | ||
newTokens.append(token) | ||
} | ||
} | ||
return newTokens | ||
} | ||
|
||
let classMappings = [ | ||
"UIView": "View", | ||
"UILabel": "TextView", | ||
"UITextField": "EditText", | ||
"UIImageView": "ImageView", | ||
"UIButton": "Button", | ||
"UITableView": "RecyclerView", | ||
"UIStackView": "LinearLayout", | ||
"UIScrollView": "ScrollView", | ||
"UISwitch": "Switch", | ||
"IBOutlet": "BindView()", | ||
"IBAction": "OnClick()" | ||
] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters