flash-notifications 0.0.17 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;kBAEqC,OAAO"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":";;kBAE8C,OAAO"}
@@ -1,15 +1,22 @@
1
1
  import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter";
2
2
  import { digg } from "diggerize";
3
- import React, { memo, useEffect } from "react";
3
+ import React, { memo, useEffect, useMemo } from "react";
4
4
  import { StyleSheet, View } from "react-native";
5
5
  import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
6
+ import useEnvironment from "@kaspernj/api-maker/build/use-environment.js";
7
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
8
+ import useStyles from "@kaspernj/api-maker/build/use-styles.js";
6
9
  import events from "../events";
7
10
  import Notification from "./notification";
8
11
  const styles = StyleSheet.create({
9
12
  view: {
10
- position: "fixed",
11
- zIndex: 99999,
12
- top: 20,
13
+ zIndex: 99999
14
+ },
15
+ viewSmDown: {
16
+ right: 20,
17
+ left: 20
18
+ },
19
+ viewMdUp: {
13
20
  right: 20
14
21
  }
15
22
  });
@@ -30,7 +37,17 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
30
37
  }, []);
31
38
  }
32
39
  render() {
33
- return (React.createElement(View, { dataSet: this.rootViewDataSet ||= { component: "flash-notifications-container" }, style: styles.view, testID: "flash-notificaitons/container" }, this.s.notifications.map((notification) => React.createElement(Notification, { count: notification.count, key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.tt.onRemovedClicked, title: notification.title, type: notification.type }))));
40
+ const { isNative } = useEnvironment();
41
+ const insets = useSafeAreaInsets();
42
+ const viewStyleFromStyles = useStyles(styles, "view");
43
+ const viewStyle = useMemo(() => [
44
+ viewStyleFromStyles,
45
+ {
46
+ position: isNative ? "absolute" : "fixed",
47
+ top: insets.top + 20
48
+ }
49
+ ], [insets.top]);
50
+ return (React.createElement(View, { dataSet: this.rootViewDataSet ||= { component: "flash-notifications-container" }, style: viewStyle, testID: "flash-notificaitons/container" }, this.s.notifications.map((notification) => React.createElement(Notification, { count: notification.count, key: `notification-${notification.count}`, message: notification.message, notification: notification, onRemovedClicked: this.tt.onRemovedClicked, title: notification.title, type: notification.type }))));
34
51
  }
35
52
  onPushNotification = (detail) => {
36
53
  const count = this.s.count + 1;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,6CAA6C,CAAA;AACzE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAC,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AAEpF,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,QAAQ,EAAE,OAAO;QACjB,MAAM,EAAE,KAAK;QACb,GAAG,EAAE,EAAE;QACP,KAAK,EAAE,EAAE;KACV;CACF,CAAC,CAAA;AAEF,eAAe,IAAI,CAAC,cAAc,CAAC,MAAM,2BAA4B,SAAQ,cAAc;IACzF,QAAQ,GAAG,EAAE,CAAA;IAEb,KAAK;QACH,IAAI,CAAC,SAAS,CAAC;YACb,KAAK,EAAE,CAAC;YACR,aAAa,EAAE,EAAE;SAClB,CAAC,CAAA;QAEF,eAAe,CAAC,MAAM,EAAE,kB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L,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC;YAChC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC;YAC5B,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;SAC3B,CAAA;QAED,IAAI,CAAC,QAAQ,CAAC,EAAC,KAAK,EAAE,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC,EAAC,CAAC,CAAA;IACpF,CAAC,CAAA;IAED,gBAAgB,GAAG,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,CAAA;IAEzF,kBAAkB,GAAG,CAAC,KAAK,EAAE,EAAE;QAC7B,IAAI,CAAC,QAAQ,CAAC;YACZ,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC1F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import useEventEmitter from \"@kaspernj/api-maker/build/use-event-emitter\"\nimport {digg} from \"diggerize\"\nimport React, {memo, useEffect} from \"react\"\nimport {StyleSheet, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\n\nimport events from \"../events\"\nimport Notification from \"./notification\"\n\nconst styles = StyleSheet.create({\n view: {\n position: \"fixed\",\n zIndex: 99999,\n top: 20,\n right: 20\n }\n})\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n timeouts = []\n\n setup() {\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventEmitter(events, \"pushNotification\", this.tt.onPushNotification)\n useEffect(() => {\n return () => {\n for (const timeout of this.tt.timeouts) {\n clearTimeout(timeout)\n }\n }\n }, [])\n }\n\n render() {\n return (\n <View\n dataSet={this.rootViewDataSet ||= {component: \"flash-notifications-container\"}}\n style={styles.view}\n testID=\"flash-notificaitons/container\"\n >\n {this.s.notifications.map((notification) =>\n <Notification\n count={notification.count}\n key={`notification-${notification.count}`}\n message={notification.message}\n notification={notification}\n onRemovedClicked={this.tt.onRemovedClicked}\n title={notification.title}\n type={notification.type}\n />\n )}\n </View>\n )\n }\n\n onPushNotification = (detail) => {\n const count = this.s.count + 1\n const timeout = setTimeout(() => this.removeNotification(count), 4000)\n\n this.tt.timeouts.push(timeout)\n\n const notification = {\n count,\n message: digg(detail, \"message\"),\n title: digg(detail, \"title\"),\n type: digg(detail, \"type\")\n }\n\n this.setState({count, notifications: this.s.notifications.concat([notification])})\n }\n\n onRemovedClicked = (notification) => this.removeNotification(digg(notification, \"count\"))\n\n removeNotification = (count) => {\n this.setState({\n notifications: this.s.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/container/index.jsx"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,6CAA6C,CAAA;AACzE,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAC9B,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AACrD,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC7C,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AACpF,OAAO,cAAc,MAAM,8CAA8C,CAAA;AACzE,OAAO,EAAC,iBAAiB,EAAC,MAAM,gCAAgC,CAAA;AAChE,OAAO,SAAS,MAAM,yCAAyC,CAAA;AAE/D,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,MAAM,gBAAgB,CAAA;AAEzC,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,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AAY,EAAE,OAAO,CAAC,CAAC,CAAA;IAEzF,kBAAkB,GAAG,CAAC,KAAK,EAAE,EAAE;QAC7B,IAAI,CAAC,QAAQ,CAAC;YACZ,aAAa,EAAE,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,IAAI,KAAK,CAAC;SAC1F,CAAC,CAAA;IACJ,CAAC,CAAA;CACF,CAAC,CAAC,CAAA","sourcesContent":["import useEventEmitter from \"@kaspernj/api-maker/build/use-event-emitter\"\nimport {digg} from \"diggerize\"\nimport React, {memo, useEffect, useMemo} from \"react\"\nimport {StyleSheet, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\nimport useEnvironment from \"@kaspernj/api-maker/build/use-environment.js\"\nimport {useSafeAreaInsets} from \"react-native-safe-area-context\"\nimport useStyles from \"@kaspernj/api-maker/build/use-styles.js\"\n\nimport events from \"../events\"\nimport Notification from \"./notification\"\n\nconst styles = StyleSheet.create({\n view: {\n zIndex: 99999\n },\n viewSmDown: {\n right: 20,\n left: 20\n },\n viewMdUp: {\n right: 20\n }\n})\n\nexport default memo(shapeComponent(class FlashNotificationsContainer extends ShapeComponent {\n timeouts = []\n\n setup() {\n this.useStates({\n count: 0,\n notifications: []\n })\n\n useEventEmitter(events, \"pushNotification\", this.tt.onPushNotification)\n useEffect(() => {\n return () => {\n for (const timeout of this.tt.timeouts) {\n clearTimeout(timeout)\n }\n }\n }, [])\n }\n\n render() {\n const {isNative} = useEnvironment()\n const insets = useSafeAreaInsets()\n const viewStyleFromStyles = useStyles(styles, \"view\")\n const viewStyle = useMemo(() => [\n viewStyleFromStyles,\n {\n position: isNative ? \"absolute\" : \"fixed\",\n top: insets.top + 20\n }\n ], [insets.top])\n\n return (\n <View\n dataSet={this.rootViewDataSet ||= {component: \"flash-notifications-container\"}}\n style={viewStyle}\n testID=\"flash-notificaitons/container\"\n >\n {this.s.notifications.map((notification) =>\n <Notification\n count={notification.count}\n key={`notification-${notification.count}`}\n message={notification.message}\n notification={notification}\n onRemovedClicked={this.tt.onRemovedClicked}\n title={notification.title}\n type={notification.type}\n />\n )}\n </View>\n )\n }\n\n onPushNotification = (detail) => {\n const count = this.s.count + 1\n const timeout = setTimeout(() => this.removeNotification(count), 4000)\n\n this.tt.timeouts.push(timeout)\n\n const notification = {\n count,\n message: digg(detail, \"message\"),\n title: digg(detail, \"title\"),\n type: digg(detail, \"type\")\n }\n\n this.setState({count, notifications: this.s.notifications.concat([notification])})\n }\n\n onRemovedClicked = (notification) => this.removeNotification(digg(notification, \"count\"))\n\n removeNotification = (count) => {\n this.setState({\n notifications: this.s.notifications.filter((notification) => notification.count != count)\n })\n }\n}))\n"]}
@@ -4,15 +4,21 @@ import PropTypesExact from "prop-types-exact";
4
4
  import React, { memo, useMemo } from "react";
5
5
  import { Pressable, StyleSheet, Text, View } from "react-native";
6
6
  import { shapeComponent, ShapeComponent } from "set-state-compare/src/shape-component";
7
+ import useStyles from "@kaspernj/api-maker/build/use-styles.js";
7
8
  const styles = StyleSheet.create({
8
9
  view: {
9
- width: 300,
10
- maxWidth: "100%",
11
10
  marginBottom: 15,
12
11
  padding: 15,
13
12
  borderRadius: 11,
14
13
  cursor: "pointer"
15
14
  },
15
+ viewSmDown: {
16
+ width: "100%"
17
+ },
18
+ viewMdUp: {
19
+ width: 300,
20
+ maxWidth: "100%"
21
+ },
16
22
  viewError: {
17
23
  border: "1px solid rgba(161, 34, 32, 0.95)",
18
24
  backgroundColor: "rgba(161, 34, 32, 0.87)"
@@ -38,7 +44,7 @@ const styles = StyleSheet.create({
38
44
  });
39
45
  const titleViewDataSet = { class: "notification-title" };
40
46
  const messageViewDataSet = { class: "notification-message" };
41
- export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
47
+ export default memo(shapeComponent(class FlashNotificationsNotification extends ShapeComponent {
42
48
  static propTypes = PropTypesExact({
43
49
  className: PropTypes.string,
44
50
  count: PropTypes.number.isRequired,
@@ -51,16 +57,11 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
51
57
  render() {
52
58
  const { count, message, title, type } = this.p;
53
59
  const { className } = this.props;
54
- const viewStyles = useMemo(() => {
55
- const viewStyles = [styles.view];
56
- if (type == "error")
57
- viewStyles.push(styles.viewError);
58
- if (type == "success")
59
- viewStyles.push(styles.viewSuccess);
60
- if (type == "alert")
61
- viewStyles.push(styles.viewAlert);
62
- return viewStyles;
63
- }, [type]);
60
+ const viewStyles = useStyles(styles, ["view", {
61
+ viewError: type == "error",
62
+ viewSuccess: type == "success",
63
+ viewAlert: type == "alert"
64
+ }]);
64
65
  const pressableDataSet = useMemo(() => ({
65
66
  class: classNames("flash-notifications-notification", className),
66
67
  type
@@ -1 +1 @@
1
- {"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AAEpF,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,MAAM;QAChB,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS;KAClB;IACD,SAAS,EAAE;QACT,MAAM,EAAE,mCAAmC;QAC3C,eAAe,EAAE,yBAAyB;KAC3C;IACD,WAAW,EAAE;QACX,MAAM,EAAE,+BAA+B;QACvC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AA;YACtD,IAAI,IAAI,IAAI,SAAS;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;YAC1D,IAAI,IAAI,IAAI,OAAO;gBAAE,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;YAEtD,OAAO,UAAU,CAAA;QACnB,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAA;QAED,MAAM,gBAAgB,GAAG,OAAO,CAC9B,GAAG,EAAE,CAAC,CAAC;YACL,KAAK,EAAE,UAAU,CAAC,kCAAkC,EAAE,SAAS,CAAC;YAChE,IAAI;SACL,CAAC,EACF,CAAC,SAAS,EAAE,IAAI,CAAC,CAClB,CAAA;QAED,OAAO,CACL,oBAAC,SAAS,IAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,gBAAgB;YACrE,oBAAC,IAAI,IAAC,KAAK,EAAE,UAAU;gBACrB,oBAAC,IAAI,IAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS;oBACtD,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,oCAAoC,KAAK,QAAQ,IACrF,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,IAAC,OAAO,EAAE,kBAAkB;oBAC/B,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,oCAAoC,KAAK,UAAU,IACzF,OAAO,CACH,CACF,CACF,CACG,CACb,CAAA;IACH,CAAC;IAED,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;CACtE,CAAC,CAAC,CAAA","sourcesContent":["import classNames from \"classnames\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\nimport React, {memo, useMemo} from \"react\"\nimport {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\n\nconst styles = StyleSheet.create({\n view: {\n width: 300,\n maxWidth: \"100%\",\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\n },\n viewError: {\n border: \"1px solid rgba(161, 34, 32, 0.95)\",\n backgroundColor: \"rgba(161, 34, 32, 0.87)\"\n },\n viewSuccess: {\n border: \"1px solid rgba(0, 0, 0, 0.95)\",\n backgroundColor: \"rgba(0, 0, 0, 0.87)\"\n },\n viewAlert: {\n border: \"1px solid rgba(204, 51, 0, 0.95)\",\n backgroundColor: \"rgba(204, 51, 0, 0.87)\"\n },\n titleview: {\n marginBottom: 5\n },\n titleText: {\n color: \"#fff\",\n fontWeight: \"bold\"\n },\n messageText: {\n color: \"#fff\"\n }\n})\n\nconst titleViewDataSet = {class: \"notification-title\"}\nconst messageViewDataSet = {class: \"notification-message\"}\n\nexport default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {\n static propTypes = PropTypesExact({\n className: PropTypes.string,\n count: PropTypes.number.isRequired,\n message: PropTypes.string.isRequired,\n notification: PropTypes.object.isRequired,\n onRemovedClicked: PropTypes.func.isRequired,\n title: PropTypes.string.isRequired,\n type: PropTypes.string.isRequired\n })\n\n render() {\n const {count, message, title, type} = this.p\n const {className} = this.props\n\n const viewStyles = useMemo(\n () => {\n const viewStyles = [styles.view]\n\n if (type == \"error\") viewStyles.push(styles.viewError)\n if (type == \"success\") viewStyles.push(styles.viewSuccess)\n if (type == \"alert\") viewStyles.push(styles.viewAlert)\n\n return viewStyles\n },\n [type]\n )\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\n type\n }),\n [className, type]\n )\n\n return (\n <Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>\n <View style={viewStyles}>\n <View dataSet={titleViewDataSet} style={styles.titleview}>\n <Text style={styles.titleText} testID={`flash-notifications/notification-${count}/title`}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText} testID={`flash-notifications/notification-${count}/message`}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
1
+ {"version":3,"file":"notification.js","sourceRoot":"","sources":["../../src/container/notification.jsx"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAA;AACnC,OAAO,SAAS,MAAM,YAAY,CAAA;AAClC,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,KAAK,EAAE,EAAC,IAAI,EAAE,OAAO,EAAC,MAAM,OAAO,CAAA;AAC1C,OAAO,EAAC,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAC,MAAM,cAAc,CAAA;AAC9D,OAAO,EAAC,cAAc,EAAE,cAAc,EAAC,MAAM,uCAAuC,CAAA;AACpF,OAAO,SAAS,MAAM,yCAAyC,CAAA;AAE/D,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,IAAI,EAAE;QACJ,YAAY,EAAE,EAAE;QAChB,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;QAChB,MAAM,EAAE,SAAS;KAClB;IACD,UAAU,EAAE;QACV,KAAK,EAAE,MAAM;KACd;IACD,QAAQ,EAAE;QACR,KAAK,EAAE,GAAG;QACV,QAAQ,EAAE,MAAM;KACjB;IACD,SAAS,EAAE;QACT,MAAM,EAAE,mCAAmC;QAC3C,eAAe,EAAE,yBAAyB;KAC3C;IACD,WAAW,EAAE;QACX,MAAM,EAAE,+BAA+B;QACvC,eAAe,EAAE,qBAAqB;KACvC;IACD,SAAS,EAAE;QACT,MAAM,EAAE,kCAAkC;QAC1C,eAAe,EAAE,wBAAwB;KAC1C;IACD,SAAS,EAAE;QACT,YAAY,EAAE,CAAC;KAChB;IACD,SAAS,EAAE;QACT,KAAK,EAAE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CAAC,CAClB,CAAA;QAED,OAAO,CACL,oBAAC,SAAS,IAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,gBAAgB;YACrE,oBAAC,IAAI,IAAC,KAAK,EAAE,UAAU;gBACrB,oBAAC,IAAI,IAAC,OAAO,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,SAAS;oBACtD,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,oCAAoC,KAAK,QAAQ,IACrF,KAAK,CACD,CACF;gBACP,oBAAC,IAAI,IAAC,OAAO,EAAE,kBAAkB;oBAC/B,oBAAC,IAAI,IAAC,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,oCAAoC,KAAK,UAAU,IACzF,OAAO,CACH,CACF,CACF,CACG,CACb,CAAA;IACH,CAAC;IAED,gBAAgB,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;CACtE,CAAC,CAAC,CAAA","sourcesContent":["import classNames from \"classnames\"\nimport PropTypes from \"prop-types\"\nimport PropTypesExact from \"prop-types-exact\"\nimport React, {memo, useMemo} from \"react\"\nimport {Pressable, StyleSheet, Text, View} from \"react-native\"\nimport {shapeComponent, ShapeComponent} from \"set-state-compare/src/shape-component\"\nimport useStyles from \"@kaspernj/api-maker/build/use-styles.js\"\n\nconst styles = StyleSheet.create({\n view: {\n marginBottom: 15,\n padding: 15,\n borderRadius: 11,\n cursor: \"pointer\"\n },\n viewSmDown: {\n width: \"100%\"\n },\n viewMdUp: {\n width: 300,\n maxWidth: \"100%\"\n },\n viewError: {\n border: \"1px solid rgba(161, 34, 32, 0.95)\",\n backgroundColor: \"rgba(161, 34, 32, 0.87)\"\n },\n viewSuccess: {\n border: \"1px solid rgba(0, 0, 0, 0.95)\",\n backgroundColor: \"rgba(0, 0, 0, 0.87)\"\n },\n viewAlert: {\n border: \"1px solid rgba(204, 51, 0, 0.95)\",\n backgroundColor: \"rgba(204, 51, 0, 0.87)\"\n },\n titleview: {\n marginBottom: 5\n },\n titleText: {\n color: \"#fff\",\n fontWeight: \"bold\"\n },\n messageText: {\n color: \"#fff\"\n }\n})\n\nconst titleViewDataSet = {class: \"notification-title\"}\nconst messageViewDataSet = {class: \"notification-message\"}\n\nexport default memo(shapeComponent(class FlashNotificationsNotification extends ShapeComponent {\n static propTypes = PropTypesExact({\n className: PropTypes.string,\n count: PropTypes.number.isRequired,\n message: PropTypes.string.isRequired,\n notification: PropTypes.object.isRequired,\n onRemovedClicked: PropTypes.func.isRequired,\n title: PropTypes.string.isRequired,\n type: PropTypes.string.isRequired\n })\n\n render() {\n const {count, message, title, type} = this.p\n const {className} = this.props\n\n const viewStyles = useStyles(styles, [\"view\", {\n viewError: type == \"error\",\n viewSuccess: type == \"success\",\n viewAlert: type == \"alert\"\n }])\n\n const pressableDataSet = useMemo(\n () => ({\n class: classNames(\"flash-notifications-notification\", className),\n type\n }),\n [className, type]\n )\n\n return (\n <Pressable dataSet={pressableDataSet} onPress={this.tt.onRemovedClicked}>\n <View style={viewStyles}>\n <View dataSet={titleViewDataSet} style={styles.titleview}>\n <Text style={styles.titleText} testID={`flash-notifications/notification-${count}/title`}>\n {title}\n </Text>\n </View>\n <View dataSet={messageViewDataSet}>\n <Text style={styles.messageText} testID={`flash-notifications/notification-${count}/message`}>\n {message}\n </Text>\n </View>\n </View>\n </Pressable>\n )\n }\n\n onRemovedClicked = () => this.p.onRemovedClicked(this.p.notification)\n}))\n"]}
package/jest.setup.js ADDED
@@ -0,0 +1,3 @@
1
+ import mockSafeAreaContext from "react-native-safe-area-context/jest/mock"
2
+
3
+ jest.mock("react-native-safe-area-context", () => mockSafeAreaContext)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flash-notifications",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "My new module",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -31,6 +31,9 @@
31
31
  "homepage": "https://github.com/kaspernj/flash-notifications#readme",
32
32
  "jest": {
33
33
  "preset": "jest-expo",
34
+ "setupFiles": [
35
+ "./jest.setup.js"
36
+ ],
34
37
  "transformIgnorePatterns": [
35
38
  "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg|diggerize|fetching-object|set-state-compare|@kaspernj/api-maker)"
36
39
  ]
@@ -50,9 +53,11 @@
50
53
  "react-native": "~0.76.9"
51
54
  },
52
55
  "peerDependencies": {
53
- "@kaspernj/api-maker": "*",
56
+ "@kaspernj/api-maker": ">= 1.0.2043",
54
57
  "expo": "*",
55
58
  "react": "*",
56
- "react-native": "*"
57
- }
59
+ "react-native": "*",
60
+ "react-native-safe-area-context": "*"
61
+ },
62
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
58
63
  }
@@ -1,17 +1,24 @@
1
1
  import useEventEmitter from "@kaspernj/api-maker/build/use-event-emitter"
2
2
  import {digg} from "diggerize"
3
- import React, {memo, useEffect} from "react"
3
+ import React, {memo, useEffect, useMemo} from "react"
4
4
  import {StyleSheet, View} from "react-native"
5
5
  import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
6
+ import useEnvironment from "@kaspernj/api-maker/build/use-environment.js"
7
+ import {useSafeAreaInsets} from "react-native-safe-area-context"
8
+ import useStyles from "@kaspernj/api-maker/build/use-styles.js"
6
9
 
7
10
  import events from "../events"
8
11
  import Notification from "./notification"
9
12
 
10
13
  const styles = StyleSheet.create({
11
14
  view: {
12
- position: "fixed",
13
- zIndex: 99999,
14
- top: 20,
15
+ zIndex: 99999
16
+ },
17
+ viewSmDown: {
18
+ right: 20,
19
+ left: 20
20
+ },
21
+ viewMdUp: {
15
22
  right: 20
16
23
  }
17
24
  })
@@ -36,10 +43,21 @@ export default memo(shapeComponent(class FlashNotificationsContainer extends Sha
36
43
  }
37
44
 
38
45
  render() {
46
+ const {isNative} = useEnvironment()
47
+ const insets = useSafeAreaInsets()
48
+ const viewStyleFromStyles = useStyles(styles, "view")
49
+ const viewStyle = useMemo(() => [
50
+ viewStyleFromStyles,
51
+ {
52
+ position: isNative ? "absolute" : "fixed",
53
+ top: insets.top + 20
54
+ }
55
+ ], [insets.top])
56
+
39
57
  return (
40
58
  <View
41
59
  dataSet={this.rootViewDataSet ||= {component: "flash-notifications-container"}}
42
- style={styles.view}
60
+ style={viewStyle}
43
61
  testID="flash-notificaitons/container"
44
62
  >
45
63
  {this.s.notifications.map((notification) =>
@@ -4,16 +4,22 @@ import PropTypesExact from "prop-types-exact"
4
4
  import React, {memo, useMemo} from "react"
5
5
  import {Pressable, StyleSheet, Text, View} from "react-native"
6
6
  import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
7
+ import useStyles from "@kaspernj/api-maker/build/use-styles.js"
7
8
 
8
9
  const styles = StyleSheet.create({
9
10
  view: {
10
- width: 300,
11
- maxWidth: "100%",
12
11
  marginBottom: 15,
13
12
  padding: 15,
14
13
  borderRadius: 11,
15
14
  cursor: "pointer"
16
15
  },
16
+ viewSmDown: {
17
+ width: "100%"
18
+ },
19
+ viewMdUp: {
20
+ width: 300,
21
+ maxWidth: "100%"
22
+ },
17
23
  viewError: {
18
24
  border: "1px solid rgba(161, 34, 32, 0.95)",
19
25
  backgroundColor: "rgba(161, 34, 32, 0.87)"
@@ -41,7 +47,7 @@ const styles = StyleSheet.create({
41
47
  const titleViewDataSet = {class: "notification-title"}
42
48
  const messageViewDataSet = {class: "notification-message"}
43
49
 
44
- export default memo(shapeComponent(class NotificationsNotification extends ShapeComponent {
50
+ export default memo(shapeComponent(class FlashNotificationsNotification extends ShapeComponent {
45
51
  static propTypes = PropTypesExact({
46
52
  className: PropTypes.string,
47
53
  count: PropTypes.number.isRequired,
@@ -56,18 +62,11 @@ export default memo(shapeComponent(class NotificationsNotification extends Shape
56
62
  const {count, message, title, type} = this.p
57
63
  const {className} = this.props
58
64
 
59
- const viewStyles = useMemo(
60
- () => {
61
- const viewStyles = [styles.view]
62
-
63
- if (type == "error") viewStyles.push(styles.viewError)
64
- if (type == "success") viewStyles.push(styles.viewSuccess)
65
- if (type == "alert") viewStyles.push(styles.viewAlert)
66
-
67
- return viewStyles
68
- },
69
- [type]
70
- )
65
+ const viewStyles = useStyles(styles, ["view", {
66
+ viewError: type == "error",
67
+ viewSuccess: type == "success",
68
+ viewAlert: type == "alert"
69
+ }])
71
70
 
72
71
  const pressableDataSet = useMemo(
73
72
  () => ({