-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(android): snackbar * remove empty description * fixes * move to UI namespace * copyright text * namespace
- Loading branch information
Showing
3 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
android/modules/ui/src/java/ti/modules/titanium/ui/android/SnackbarProxy.java
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,45 @@ | ||
/** | ||
* TiDev Titanium Mobile | ||
* Copyright TiDev, Inc. 04/07/2022-Present | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
package ti.modules.titanium.ui.android; | ||
|
||
import android.app.Activity; | ||
|
||
import com.google.android.material.snackbar.Snackbar; | ||
|
||
import org.appcelerator.kroll.annotations.Kroll; | ||
import org.appcelerator.titanium.proxy.TiViewProxy; | ||
import org.appcelerator.titanium.view.TiUIView; | ||
|
||
import ti.modules.titanium.ui.widget.TiUISnackbar; | ||
|
||
@Kroll.proxy(creatableInModule = AndroidModule.class) | ||
public class SnackbarProxy extends TiViewProxy | ||
{ | ||
private static final String TAG = "SnackbarProxy"; | ||
|
||
@Kroll.constant | ||
public static final int LENGTH_LONG = Snackbar.LENGTH_LONG; | ||
@Kroll.constant | ||
public static final int LENGTH_SHORT = Snackbar.LENGTH_SHORT; | ||
@Kroll.constant | ||
public static final int LENGTH_INDEFINITE = Snackbar.LENGTH_INDEFINITE; | ||
|
||
private TiUISnackbar snackbar; | ||
|
||
@Override | ||
public TiUIView createView(Activity activity) | ||
{ | ||
snackbar = new TiUISnackbar(this); | ||
return snackbar; | ||
} | ||
|
||
@Kroll.method | ||
public void show() | ||
{ | ||
snackbar.showMessage(); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
android/modules/ui/src/java/ti/modules/titanium/ui/widget/TiUISnackbar.java
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,53 @@ | ||
/** | ||
* TiDev Titanium Mobile | ||
* Copyright TiDev, Inc. 04/07/2022-Present | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
package ti.modules.titanium.ui.widget; | ||
|
||
import android.view.View; | ||
|
||
import com.google.android.material.snackbar.Snackbar; | ||
|
||
import org.appcelerator.kroll.KrollDict; | ||
import org.appcelerator.titanium.TiC; | ||
import org.appcelerator.titanium.proxy.TiViewProxy; | ||
import org.appcelerator.titanium.util.TiConvert; | ||
import org.appcelerator.titanium.view.TiUIView; | ||
|
||
public class TiUISnackbar extends TiUIView | ||
{ | ||
private static final String TAG = "TiUISnackbar"; | ||
|
||
public TiUISnackbar(TiViewProxy proxy) | ||
{ | ||
super(proxy); | ||
} | ||
|
||
public void showMessage() | ||
{ | ||
View view = this.parent.getOrCreateView().getNativeView(); | ||
|
||
String message = ""; | ||
if (proxy.hasProperty(TiC.PROPERTY_MESSAGE)) { | ||
message = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_MESSAGE)); | ||
} | ||
|
||
int length = Snackbar.LENGTH_SHORT; | ||
if (proxy.hasProperty(TiC.PROPERTY_LENGTH)) { | ||
length = TiConvert.toInt(proxy.getProperty(TiC.PROPERTY_LENGTH), Snackbar.LENGTH_SHORT); | ||
} | ||
|
||
Snackbar snack = Snackbar.make(view, message, length); | ||
if (proxy.hasProperty(TiC.PROPERTY_ACTION)) { | ||
String action = TiConvert.toString(proxy.getProperty(TiC.PROPERTY_ACTION)); | ||
snack.setAction(action, v -> { | ||
KrollDict kd = new KrollDict(); | ||
kd.put("action", action); | ||
fireEvent(TiC.EVENT_CLICK, kd); | ||
}); | ||
} | ||
snack.show(); | ||
} | ||
} |
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,86 @@ | ||
--- | ||
name: Titanium.UI.Android.Snackbar | ||
summary: Snackbars provide brief messages about app processes at the bottom of the screen. | ||
description: | | ||
For design guidelines, see | ||
[Material design: Snackbars](https://material.io/components/snackbars) | ||
since: "11.1.0" | ||
platforms: [android] | ||
|
||
methods: | ||
- name: show | ||
summary: Show the Snackbar | ||
|
||
events: | ||
- name: click | ||
summary: Fired when the action button is clicked | ||
properties: | ||
- name: action | ||
summary: The text of the action button. | ||
type: String | ||
|
||
properties: | ||
- name: LENGTH_SHORT | ||
summary: | | ||
Use with `length` to specify the display time. | ||
type: Number | ||
permission: read-only | ||
|
||
- name: LENGTH_LONG | ||
summary: | | ||
Use with `length` to specify the display time. | ||
type: Number | ||
permission: read-only | ||
|
||
- name: LENGTH_INDEFINITE | ||
summary: | | ||
Use with `length` to specify the display time. | ||
type: Number | ||
permission: read-only | ||
|
||
- name: length | ||
summary: Display time of the Snackbar | ||
description: | | ||
Use with on of the constants: `Ti.UI.Android.Snackbar.LENGTH_SHORT`, | ||
`Ti.UI.Android.Snackbar.LENGTH_LONG` or | ||
`Ti.UI.Android.Snackbar.LENGTH_INDEFINITE` | ||
type: Number | ||
default: LENGTH_SHORT | ||
since: "10.2.0" | ||
|
||
- name: action | ||
summary: Text of the right hand action button | ||
type: String | ||
since: "10.2.0" | ||
|
||
- name: message | ||
summary: Text of Snackbar | ||
type: String | ||
since: "10.2.0" | ||
|
||
examples: | ||
- title: Show a Snackbar | ||
example: | | ||
Display a Snackbar with an action button. | ||
``` js | ||
const win = Ti.UI.createWindow(); | ||
const btn = Ti.UI.createButton({ | ||
title: 'show message' | ||
}); | ||
btn.addEventListener('click', function() { | ||
snack.show(); | ||
}); | ||
const snack = Ti.UI.Android.createSnackbar({ | ||
message: 'Hello Snackbar!', | ||
length: Ti.UI.Android.Snackbar.LENGTH_INDEFINITE, | ||
action: 'click me' | ||
}); | ||
snack.addEventListener('click', function(e) { | ||
console.log(e.action); | ||
}); | ||
win.add([btn, snack]); | ||
win.open(); | ||
``` |