mirror of
https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin.git
synced 2026-07-31 00:02:14 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
55856bcb44 | ||
|
|
28cc48357c | ||
|
|
4399bed9e1 | ||
|
|
09d536b9ec | ||
|
|
653aed37a3 | ||
|
|
82f72d2da7 | ||
|
|
440ea5bded | ||
|
|
8869b81749 | ||
|
|
e4e18f143a | ||
|
|
9757e2c04c | ||
|
|
791beb0bc4 | ||
|
|
fde8da464f | ||
|
|
dbf27e63a4 | ||
|
|
3235b9c8e3 | ||
|
|
ed2398455a | ||
|
|
2a0ecbc2dd | ||
|
|
6351512cf1 | ||
|
|
206b7e014e | ||
|
|
a429424107 | ||
|
|
4324168d2a | ||
|
|
75287f6517 | ||
|
|
04b4cf7894 |
@@ -0,0 +1,4 @@
|
||||
.idea/
|
||||
screenshots/
|
||||
test/
|
||||
issue_template.md
|
||||
@@ -32,18 +32,15 @@ This plugin allows you to show a native Toast (a little text popup) on iOS, Andr
|
||||
It's great for showing a non intrusive native notification which is guaranteed always in the viewport of the browser.
|
||||
* You can choose where to show the Toast: at the top, center or bottom of the screen.
|
||||
* You can choose two durations: short (approx. 2 seconds), or long (approx. 5 seconds), after which the Toast automatically disappears.
|
||||
* Compatible with [Cordova Plugman](https://github.com/apache/cordova-plugman).
|
||||
* Officially supported by [PhoneGap Build](https://build.phonegap.com/plugins).
|
||||
* Minimum iOS version is [6](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/7).
|
||||
|
||||
Example usages:
|
||||
* "There were validation errors"
|
||||
* "Account created successfully"
|
||||
* "The record was deleted"
|
||||
* "Login successful"
|
||||
* "The battery is almost dead"
|
||||
* "You are now logged out"
|
||||
* "Connection failure, please try again later"
|
||||
* "Created Order #00287
|
||||
|
||||
## 2. Screenshots
|
||||
|
||||
@@ -234,7 +231,7 @@ called again. You can distinguish between those events of course:
|
||||
);
|
||||
```
|
||||
|
||||
The success callback is useful when your toast is binded to a notification id in your backend and you have to mark it as `read` when the toast is done, or to update the notifications counter for iOS. The usage of this will be defined by your application logic. Use the `result.data` object to support your specific logic.
|
||||
The success callback is useful when your toast is bound to a notification id in your backend and you have to mark it as `read` when the toast is done, or to update the notifications counter for iOS. The usage of this will be defined by your application logic. Use the `result.data` object to support your specific logic.
|
||||
|
||||
### Styling
|
||||
Since version 2.4.0 you can pass an optional `styling` object to the plugin.
|
||||
@@ -276,6 +273,10 @@ The Android code was entirely created by me.
|
||||
For iOS most credits go to this excellent [Toast for iOS project by Charles Scalesse] (https://github.com/scalessec/Toast).
|
||||
|
||||
## 6. CHANGELOG
|
||||
- 2.7.2: Even better Android compatibility, but you're limited to short and long durations now, on Android.
|
||||
- 2.7.0: [Android P compatibility.](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/116)
|
||||
- 2.6.2: [iOS view hierarchy fix.](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/pull/112)
|
||||
- 2.6.0: Windows support!
|
||||
- 2.5.2: Multi-line wrapping Toasts are now center aligned.
|
||||
- 2.5.1: You can now specify the `textSize` used in the font for iOS and Android.
|
||||
- 2.5.0: By popular demand: Specify the duration of the Toast on iOS and Android. Pass in `short` (2000ms), `long` (4000ms), or any nr of milliseconds: `900`.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-x-toast",
|
||||
"version": "2.6.0",
|
||||
"version": "2.7.3",
|
||||
"description": "This plugin allows you to show a Toast. A Toast is a little non intrusive buttonless popup which automatically disappears.",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-x-toast",
|
||||
|
||||
+3
-7
@@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cordova-plugin-x-toast"
|
||||
version="2.6.0">
|
||||
version="2.7.3">
|
||||
|
||||
<name>Toast</name>
|
||||
|
||||
@@ -29,9 +28,6 @@
|
||||
<clobbers target="window.plugins.toast" />
|
||||
</js-module>
|
||||
|
||||
<js-module src="test/tests.js" name="tests">
|
||||
</js-module>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
|
||||
@@ -80,7 +76,7 @@
|
||||
<feature name="Toast" value="Toast" />
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
|
||||
<!-- windows -->
|
||||
<platform name="windows">
|
||||
<js-module src="src/windows/toastProxy.js" name="ToastProxy">
|
||||
@@ -90,5 +86,5 @@
|
||||
<feature name="Toast" value="Toast" />
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
|
||||
</plugin>
|
||||
|
||||
@@ -35,7 +35,10 @@ public class Toast extends CordovaPlugin {
|
||||
private android.widget.Toast mostRecentToast;
|
||||
private ViewGroup viewGroup;
|
||||
|
||||
private static final boolean IS_AT_LEAST_JELLY_BEAN = Build.VERSION.SDK_INT >= 16;
|
||||
private static final boolean IS_AT_LEAST_LOLLIPOP = Build.VERSION.SDK_INT >= 21;
|
||||
private static final boolean IS_AT_LEAST_PIE = Build.VERSION.SDK_INT >= 28;
|
||||
private static final boolean IS_AT_LEAST_R = Build.VERSION.SDK_INT >= 30;
|
||||
|
||||
// note that webView.isPaused() is not Xwalk compatible, so tracking it poor-man style
|
||||
private boolean isPaused;
|
||||
@@ -89,7 +92,7 @@ public class Toast extends CordovaPlugin {
|
||||
final android.widget.Toast toast = android.widget.Toast.makeText(
|
||||
IS_AT_LEAST_LOLLIPOP ? cordova.getActivity().getWindow().getContext() : cordova.getActivity().getApplicationContext(),
|
||||
message,
|
||||
android.widget.Toast.LENGTH_LONG // actually controlled by a timer further down
|
||||
"short".equalsIgnoreCase(duration) ? android.widget.Toast.LENGTH_SHORT : android.widget.Toast.LENGTH_LONG
|
||||
);
|
||||
|
||||
if ("top".equals(position)) {
|
||||
@@ -104,7 +107,8 @@ public class Toast extends CordovaPlugin {
|
||||
}
|
||||
|
||||
// if one of the custom layout options have been passed in, draw our own shape
|
||||
if (styling != null && Build.VERSION.SDK_INT >= 16) {
|
||||
// (but disabled on Android >= 11 since custom toast views are deprecated)
|
||||
if (styling != null && IS_AT_LEAST_JELLY_BEAN && !IS_AT_LEAST_R) {
|
||||
|
||||
// the defaults mimic the default toast as close as possible
|
||||
final String backgroundColor = styling.optString("backgroundColor", "#333333");
|
||||
@@ -131,14 +135,18 @@ public class Toast extends CordovaPlugin {
|
||||
toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);
|
||||
|
||||
// this gives the toast a very subtle shadow on newer devices
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
if (IS_AT_LEAST_LOLLIPOP) {
|
||||
toast.getView().setElevation(6);
|
||||
}
|
||||
}
|
||||
|
||||
// On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener',
|
||||
// so created something funky that compares the Toast position to the tap coordinates.
|
||||
if (IS_AT_LEAST_LOLLIPOP) {
|
||||
if (IS_AT_LEAST_R) {
|
||||
// On Android >= 11 the 'toast.getView()' will always return null
|
||||
// so no touchListener can be used or mocked
|
||||
// DO NOTHING
|
||||
} else if (IS_AT_LEAST_LOLLIPOP) {
|
||||
// On Android >= 5 you can no longer rely on the 'toast.getView().setOnTouchListener',
|
||||
// so created something funky that compares the Toast position to the tap coordinates.
|
||||
getViewGroup().setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
@@ -192,7 +200,13 @@ public class Toast extends CordovaPlugin {
|
||||
}
|
||||
// trigger show every 2500 ms for as long as the requested duration
|
||||
_timer = new CountDownTimer(hideAfterMs, 2500) {
|
||||
public void onTick(long millisUntilFinished) {toast.show();}
|
||||
public void onTick(long millisUntilFinished) {
|
||||
// see https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/116
|
||||
// and https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/issues/120
|
||||
// if (!IS_AT_LEAST_PIE) {
|
||||
// toast.show();
|
||||
// }
|
||||
}
|
||||
public void onFinish() {
|
||||
returnTapEvent("hide", msg, data, callbackContext);
|
||||
toast.cancel();
|
||||
@@ -257,4 +271,4 @@ public class Toast extends CordovaPlugin {
|
||||
public void onResume(boolean multitasking) {
|
||||
this.isPaused = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ static id styling;
|
||||
}
|
||||
|
||||
- (UIViewController*) getTopMostViewController {
|
||||
UIViewController *presentingViewController = [[[UIApplication sharedApplication] delegate] window].rootViewController;
|
||||
UIViewController *presentingViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
|
||||
while (presentingViewController.presentedViewController != nil) {
|
||||
presentingViewController = presentingViewController.presentedViewController;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user