-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(android): use handlebar templates to bind real properties/functi…
…ons instead of using extensions (#173)
- Loading branch information
Showing
27 changed files
with
567 additions
and
376 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
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
26 changes: 3 additions & 23 deletions
26
packages/targets/sources/android/android.component.handlebars
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 |
---|---|---|
@@ -1,24 +1,4 @@ | ||
{{#if hasProperties}} | ||
data class {{{componentName}}}( | ||
{{#if singleton}} | ||
{{#each properties}} | ||
val {{{@key}}}: {{{this.type}}} = {{{this.initializer}}}{{#unless @last}},{{/unless}} | ||
{{/each}} | ||
{{else}} | ||
{{#each properties}} | ||
val {{{@key}}}: {{{this.type}}}{{#unless @last}},{{/unless}} | ||
{{/each}} | ||
{{/if}} | ||
{{else}} | ||
data class {{{componentName}}}( | ||
val nonce: String = "" | ||
{{/if}} | ||
{{#if public}}) : StateBag { | ||
companion object {} | ||
override val name = "{{{componentName}}}" | ||
package {{{packageName}}} | ||
|
||
{{> androidDataClassStart }} | ||
} | ||
{{else}} | ||
) { | ||
companion object {} | ||
} | ||
{{/if}} |
22 changes: 22 additions & 0 deletions
22
packages/targets/sources/android/android.data-class.start.handlebars
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,22 @@ | ||
{{#if hasProperties}} | ||
data class {{{componentName}}}( | ||
{{#if singleton}} | ||
{{#each properties}} | ||
val {{{@key}}}: {{{this.type}}} = {{{this.initializer}}}{{#unless @last}},{{/unless}} | ||
{{/each}} | ||
{{else}} | ||
{{#each properties}} | ||
val {{{@key}}}: {{{this.type}}}{{#unless @last}},{{/unless}} | ||
{{/each}} | ||
{{/if}} | ||
{{else}} | ||
data class {{{componentName}}}( | ||
val nonce: String = "" | ||
{{/if}} | ||
{{#if public}}) : StateBag { | ||
companion object {} | ||
override val name = "{{{componentName}}}" | ||
{{else}} | ||
) { | ||
companion object {} | ||
{{/if}} |
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 |
---|---|---|
@@ -1,13 +1,18 @@ | ||
package {{{packageName}}} | ||
|
||
import android.graphics.Color as CoreColor | ||
import android.support.v4.graphics.ColorUtils | ||
|
||
val Color.color: Int | ||
get() { | ||
val rgb = ColorUtils.HSLToColor(floatArrayOf(this.h * 360, this.s, this.l)) | ||
return CoreColor.argb( | ||
(this.a * 255).toInt(), | ||
CoreColor.red(rgb), | ||
CoreColor.green(rgb), | ||
CoreColor.blue(rgb) | ||
) | ||
} | ||
{{> androidDataClassStart }} | ||
|
||
val color: Int | ||
get() { | ||
val rgb = ColorUtils.HSLToColor(floatArrayOf(this.h * 360, this.s, this.l)) | ||
return CoreColor.argb( | ||
(this.a * 255).toInt(), | ||
CoreColor.red(rgb), | ||
CoreColor.green(rgb), | ||
CoreColor.blue(rgb) | ||
) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,53 +1,57 @@ | ||
package {{{packageName}}} | ||
|
||
import android.net.Uri | ||
import java.net.URL | ||
|
||
private val extensionReplacer = """(.+)(_.+)""".toRegex() | ||
private val fileReplacer = """[^a-z0-9_]""".toRegex() | ||
{{> androidDataClassStart }} | ||
|
||
internal val File.resourceName: String | ||
get() { | ||
return extensionReplacer.replace(fileReplacer.replace(src.toLowerCase(), "_"), "$1") | ||
} | ||
|
||
private val File.resourcePath: String | ||
get() { | ||
return "$type/$resourceName" | ||
} | ||
|
||
internal val File.resourceId: Int | ||
get() { | ||
return Environment.resources.getIdentifier( | ||
resourceName, | ||
type, | ||
Environment.packageName | ||
) | ||
} | ||
|
||
internal val File.canonicalURL: String | ||
get() { | ||
if (Environment.isHot) { | ||
return "${Environment.serverUrl}/$src" | ||
val uri: Uri | ||
get() { | ||
return Uri.parse(this.canonicalURL) | ||
} | ||
|
||
return "android.resource://${Environment.packageName}/$resourcePath" | ||
} | ||
val url: URL | ||
get() { | ||
return URL(this.canonicalURL) | ||
} | ||
|
||
internal val File.websafeURL: String | ||
get() { | ||
if (Environment.isHot) { | ||
return canonicalURL | ||
internal val resourceName: String | ||
get() { | ||
return extensionReplacer.replace(fileReplacer.replace(src.toLowerCase(), "_"), "$1") | ||
} | ||
|
||
return "file:///android_res/$resourcePath" | ||
} | ||
internal val resourceId: Int | ||
get() { | ||
return Environment.resources.getIdentifier( | ||
resourceName, | ||
type, | ||
Environment.packageName | ||
) | ||
} | ||
|
||
internal val canonicalURL: String | ||
get() { | ||
if (Environment.isHot) { | ||
return "${Environment.serverUrl}/$src" | ||
} | ||
|
||
val File.uri: Uri | ||
get() { | ||
return Uri.parse(this.canonicalURL) | ||
} | ||
return "android.resource://${Environment.packageName}/$resourcePath" | ||
} | ||
|
||
internal val websafeURL: String | ||
get() { | ||
if (Environment.isHot) { | ||
return canonicalURL | ||
} | ||
|
||
val File.url: URL | ||
get() { | ||
return URL(this.canonicalURL) | ||
} | ||
return "file:///android_res/$resourcePath" | ||
} | ||
|
||
private val resourcePath: String | ||
get() { | ||
return "$type/$resourceName" | ||
} | ||
} | ||
|
||
private val extensionReplacer = """(.+)(_.+)""".toRegex() | ||
private val fileReplacer = """[^a-z0-9_]""".toRegex() |
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
Oops, something went wrong.