Skip to content

Instantly share code, notes, and snippets.

View vadimkorr's full-sized avatar
🦉

Vadim vadimkorr

🦉
View GitHub Profile
@vadimkorr
vadimkorr / NotificationBase.js
Last active August 23, 2019 14:44
Passing type via props
import React from "react";
import PropTypes from "prop-types";
import { StyleSheet, TouchableOpacity, Text } from "react-native";
import { FontAwesome } from "@expo/vector-icons";
const ICON_SQUARE_SIZE_PX = 100;
// returns configuration depending on notification type
const getConfigByType = type => {
switch (type) {
@vadimkorr
vadimkorr / SuccessNotification.js
Last active July 30, 2019 10:19
Implementation with NotificationBase component
import React from "react";
import { NotificationBase } from "./NotificationBase";
import PropTypes from "prop-types";
export const SuccessNotification = props => (
<NotificationBase
{...props}
colorPrimary="#dff0d8"
colorAccent="#3c763d"
iconName="check-circle"
@vadimkorr
vadimkorr / NotificationControls.js
Last active August 23, 2019 14:40
Example of accessing state directly
// trying to push notification object directly to the array
store.notifications.push(
createSuccessNotification(
"Success",
"This message tells that everything goes fine."
)
)
@vadimkorr
vadimkorr / App.js
Last active February 27, 2019 19:00
import React from "react";
import { Routing } from "./src/Routing";
import { configure } from "mobx";
configure({
// 'observed' means that the state needs to be changed through actions
// otherwise it throws an error
enforceActions: "observed"
});
@vadimkorr
vadimkorr / makeNotification.js
Last active July 30, 2019 10:27
Implementation with hooks
import React from "react";
import PropTypes from "prop-types";
import { StyleSheet, TouchableOpacity, Text, Animated } from "react-native";
import { FontAwesome } from "@expo/vector-icons";
const ICON_SQUARE_SIZE_PX = 100;
const ANIMATION_DURATION_MS = 150;
const NOTIFICATION_HEIGHT_PX = 120;
export const makeNotification = (iconName, colorPrimary, colorAccent) => {
@vadimkorr
vadimkorr / makeNotification.js
Last active April 10, 2019 07:09
Implementation with animations
import React from "react";
import PropTypes from "prop-types";
import { StyleSheet, TouchableOpacity, Text, Animated } from "react-native";
import { FontAwesome } from "@expo/vector-icons";
const ICON_SQUARE_SIZE_PX = 100;
const ANIMATION_DURATION_MS = 150;
const NOTIFICATION_HEIGHT_PX = 120;
export const makeNotification = (iconName, colorPrimary, colorAccent) => {
import React from "react";
import PropTypes from "prop-types";
import { View } from "react-native";
import { observer } from "mobx-react";
import { Notification } from "../Notification";
import { NotificationsStore, withNotifications } from "../store";
// 'observer' function turns component into reactive component
// component will be rerendered upon 'notifications' array change
const NotificationsInner = observer(props => {
import { observable, action, computed } from "mobx";
export class NotificationsStore {
constructor(notifications) {
this.notifications = [...notifications];
}
// Observers will be notified and react to changes
// in properties which have @observable decorator.
@observable
import React from "react";
import PropTypes from "prop-types";
import { View } from "react-native";
import { Button, NotificationsStore, withNotifications } from "../../components";
// description of buttons which add notifications
const controls = [{
key: "create-success-notification-button",
iconName: "check",
colorPrimary: "#cbf0c4",
import { makeNotification } from "./makeNotification";
export const InfoNotification = makeNotification(
"info-circle",
"#d9edf7",
"#31708f"
);