Skip to content

Commit 7f77a70

Browse files
AdamAtriedusperoni
andauthored
feat(feedback): adds feedback over dialog on android (#11)
* adds feedback toast over dialog * cast dialog as android specific View * updates View import, and casts dialog option as <any> * fix: fallback to foregroundActivity if dialog not found * fix: null coalesce android options --------- Co-authored-by: Eduardo Speroni <[email protected]>
1 parent 97f2678 commit 7f77a70

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

apps/demo/src/plugin-demos/nativescript-feedback.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Button text="Another custom font" tap="{{ showCustomFont2 }}" class="button button-font" />
1717
<Button text="Black icon" tap="{{ showBlackCustomIcon }}" class="button button-custom-alt" />
1818
<Button text="Hide!" tap="{{ hide }}" class="button button-hide" />
19+
<Button text="Over dialog" tap="{{ showOverDialog }}" class="button button-custom" />
1920
</WrapLayout>
2021
</StackLayout>
2122
</ScrollView>

packages/nativescript-feedback/common.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color } from '@nativescript/core';
1+
import { Color, View } from '@nativescript/core';
22

33
export enum FeedbackPosition {
44
Top,
@@ -121,6 +121,11 @@ export interface FeedbackShowOptions {
121121
* Default true.
122122
*/
123123
iconPulseEnabled?: boolean;
124+
125+
/***
126+
* A view that will be shown modally
127+
*/
128+
dialog?: View;
124129
};
125130
}
126131

packages/nativescript-feedback/index.android.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { FeedbackCommon, FeedbackShowOptions, FeedbackHideOptions, FeedbackType, FeedbackPosition } from './common';
2-
import { Application, Color, Utils } from '@nativescript/core';
2+
import { Application, Color, Utils, View } from '@nativescript/core';
33

44
export { FeedbackType };
55
export { FeedbackPosition };
@@ -10,7 +10,8 @@ export class Feedback extends FeedbackCommon {
1010
show(options: FeedbackShowOptions): Promise<void> {
1111
return new Promise<void>((resolve) => {
1212
this.lastAlert = null;
13-
const alerter = com.tapadoo.alerter.Alerter.create(Application.android.foregroundActivity)
13+
const activityOrDialog = (options?.android?.dialog as any)?._dialogFragment?.getDialog() || Application.android.foregroundActivity;
14+
const alerter = com.tapadoo.alerter.Alerter.create(activityOrDialog)
1415
.setLayoutGravity(Feedback.getPosition(options.position))
1516
.setIconColorFilter(0)
1617
.setDuration(options.duration ? options.duration : 4000);

tools/demo/nativescript-feedback/index.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color, isIOS } from '@nativescript/core';
1+
import { alert, Button, Color, EventData, GridLayout, isIOS, Label } from '@nativescript/core';
22
import { Feedback, FeedbackPosition, FeedbackType } from '@valor/nativescript-feedback';
33
import { DemoSharedBase } from '../utils';
44

@@ -142,4 +142,47 @@ export class DemoSharedNativescriptFeedback extends DemoSharedBase {
142142
public hide(): void {
143143
this.feedback.hide();
144144
}
145+
146+
public showOverDialog(args: EventData): void {
147+
const page = (<Button>args.object).page;
148+
const grid = new GridLayout();
149+
(<any>grid).rows = '*';
150+
(<any>grid).columns = '*';
151+
grid.height = 280;
152+
grid.width = 400;
153+
grid.backgroundColor = '#5d0239';
154+
const label = new Label();
155+
label.horizontalAlignment = 'center';
156+
label.verticalAlignment = 'middle';
157+
label.text = 'This is a dialog';
158+
label.fontSize = 18;
159+
label.color = new Color('#FFFFFF');
160+
grid.addChild(label);
161+
162+
const dialog = page.showModal(grid, {
163+
context: null,
164+
fullscreen: false,
165+
animated: true,
166+
stretched: false,
167+
closeCallback: () => console.log('closed dialog'),
168+
});
169+
170+
grid.on('tap', () => page.closeModal());
171+
172+
setTimeout(async () => {
173+
await this.feedback.success({
174+
title: 'Over dialog',
175+
titleSize: 17,
176+
messageSize: 14,
177+
message: "I'm configured to show over a modal presentation.",
178+
duration: 3000,
179+
titleFont: isIOS ? 'SourceSansPro-Bold' : 'SourceSansPro-Bold.otf',
180+
messageFont: isIOS ? 'Source Sans Pro' : 'SourceSansPro.otf',
181+
onTap: () => console.log('over dialog tapped'),
182+
android: { dialog },
183+
});
184+
console.log('closed toast');
185+
setTimeout(() => dialog.closeModal(), 5000);
186+
}, 1000);
187+
}
145188
}

0 commit comments

Comments
 (0)