Skip to content

Commit

Permalink
Added typed builder
Browse files Browse the repository at this point in the history
  • Loading branch information
wainwrightmark committed Mar 14, 2023
1 parent 506f02c commit 3d89770
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 111 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Possible header types:
- `Bug Fixes` for any bug fixes.
- `Breaking Changes` for any backwards-incompatible changes.#

## v0.5.0 (2023-03-14)
- Features - Added support for Preferences Plugin
- Features - Derive a typed builder for some types
- Breaking Changes - Added more support for Local Notifications

## v0.4.0 (2023-03-06)
- Features - Added support for Screen Reader plugin

Expand Down
30 changes: 21 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "capacitor_bindings"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
authors = ["Mark Wainwright <wainwrightml@gmail.com>"]
description = "Capactior bindings to help you build android and ios apps with rust."
Expand All @@ -18,6 +18,7 @@ js-sys = "0.3"
serde = { version = "1", features = ["derive"] }
serde-wasm-bindgen = "0.5"
serde_with = "2.2.0"
typed-builder = "0.14.0"
wasm-bindgen = { version = "0.2" }
wasm-bindgen-futures = "0.4"

Expand All @@ -28,4 +29,4 @@ serde_json = "1"
[features]
web =[]
android = []
ios = []
ios = []
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
</application>

<!-- Permissions -->

<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
46 changes: 10 additions & 36 deletions example_application/src/notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,16 @@ pub fn notification_view() -> Html {

fn schedule_notifications() {
do_and_toast_result(|| {
let options = ScheduleOptions {
notifications: vec![LocalNotificationSchema {
auto_cancel: true,
body: "Notification Body".to_string(),
title: "Notification Title".to_string(),
schedule: Schedule {
on: ScheduleOn {
second: Some(0),
year: None,
minute: None,
month: None,
day: None,
weekday: None,
hour: None,
},
allow_while_idle: true,
},
large_body: Some("Notification Large Body".to_string()),
summary_text: Some("Notification Summary Text".to_string()),
id: 123,
ongoing: false,
inbox_list: Some(vec![
"N One".to_string(),
"N Two".to_string(),
"N Three".to_string(),
"N Four".to_string(),
"N Five".to_string(),
]),
action_type_id: Some("MyActionType".to_string()),
group: None,
group_summary: None,
small_icon: None,
large_icon: None,
icon_color: None,
}],
};
let options = LocalNotificationSchema::builder()
.title("Notification Title")
.body("Notification Body")
.auto_cancel(true)
.schedule(ScheduleOn::builder().second(0).build())
.id(123)
.large_body("Notification Large Body")
.summary_text("Notification Summary Text")
.inbox_list(vec!["N One".into(), "N Two".into(), "N Three".into(), "N Four".into(), "N Five".into()])
.build();

LocalNotifications::schedule(options)
});
Expand Down
20 changes: 17 additions & 3 deletions src/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
use typed_builder::TypedBuilder;
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};

use crate::helpers::*;
Expand Down Expand Up @@ -38,13 +39,16 @@ impl Dialog {
}

#[skip_serializing_none]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(TypedBuilder, Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct AlertOptions {
#[builder(setter(into))]
/// Title of the dialog.
pub title: String,
#[builder(setter(into))]
/// Message to show on the dialog.
pub message: String,
#[builder(setter(into))]
/// Text to use on the action button.
pub button_title: String,
}
Expand All @@ -60,19 +64,25 @@ pub struct PromptResult {
}

#[skip_serializing_none]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(TypedBuilder, Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct PromptOptions {
#[builder(setter(into))]
/// Title of the dialog.
pub title: String,
#[builder(setter(into))]
/// Message to show on the dialog.
pub message: String,
#[builder(setter(into))]
/// Text to use on the positive action button.
pub ok_button_title: String,
#[builder(setter(into))]
/// Text to use on the negative action button.
pub cancel_button_title: String,
#[builder(setter(into, strip_option), default)]
/// Placeholder text for hints.
pub input_placeholder: Option<String>,
#[builder(setter(into, strip_option), default)]
/// Prepopulated text.
pub input_text: Option<String>,
}
Expand All @@ -86,15 +96,19 @@ pub struct ConfirmResult {
}

#[skip_serializing_none]
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[derive(TypedBuilder, Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct ConfirmOptions {
#[builder(setter(into))]
/// Title of the dialog.
pub title: String,
#[builder(setter(into))]
/// Message to show on the dialog.
pub message: String,
#[builder(setter(into))]
/// Text to use on the positive action button.
pub ok_button_title: String,
#[builder(setter(into))]
/// Text to use on the negative action button.
pub cancel_button_title: String,
}

0 comments on commit 3d89770

Please sign in to comment.