12.0.40 • Published 8 months ago

kitcheningredients v12.0.40

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

About

Helper for a base app template with a Directus Backend based on NativeBase. Written for React Web & React Native. Designed for an expo app.

  • Login System to Directus
  • React & React Native (expo)
  • Based on NativeBase
  • Synchronised States
  • Synchronised Storage
  • Easy Routing
  • Lottie Files

Installation

npm install kitcheningredients

Usage

import { registerRootComponent } from 'expo';
import {App, ConfigHolder} from 'kitcheningredients'
import {MyDirectusStorage} from "kitcheningredients/lib/module/ignoreCoverage/KitchenHelper/storage/MyDirectusStorage";
import Project from "./src/project/Project";
import nativebaseConfig from "./nativebase.config";
import styleConfig from "./styleConfig.json";
import config from "./config.json";
import currentpackageJson from "./package.json";
import currentpackageJsonLock from "./package-lock.json";
import thirdpartyLicense from "./thirdpartyLicense.json"
import AppConfig from "./app.config"

ConfigHolder.instance.storage = new MyDirectusStorage();
ConfigHolder.plugin = new Project()
ConfigHolder.nativebaseConfig = nativebaseConfig
ConfigHolder.styleConfig = styleConfig
ConfigHolder.config = config
ConfigHolder.currentpackageJson = currentpackageJson
ConfigHolder.currentpackageJsonLock = currentpackageJsonLock
ConfigHolder.thirdpartyLicense = thirdpartyLicense
ConfigHolder.AppConfig = AppConfig

registerRootComponent(App);
import {ServerAPI} from "kitcheningredients";

export const TestDownload = (props) => {
  async function download(){
    let directus = ServerAPI.getClient();
    const articles = await directus.items('articles').readByQuery({});
  }
}

To get the logged in user and corresponding role you can use:

import {ConfigHolder} from "kitcheningredients";

let roleInstance = ConfigHolder.instance.getRole();
let userInstance = ConfigHolder.instance.getUser();
import {Example} from "./screens/example/Example";
import {BaseTemplate, PluginInterface, Menu, MenuItem} from "kitcheningredients";

export default class Project implements PluginInterface {

    //...

  registerRoutes() {
      //Register your screen with the BaseTemplate or any other you like
      Menu.registerRoute(Example, BaseTemplate, "Example", "example");
      let myMenu = new MenuItem("ExampleMenu", "ExampleMenu", null, null, null, null, true);
      Menu.registerCommonMenu(myMenu);
      myMenu.addChildMenuItems(new MenuItem("ExampleItem", "ExampleItem", Example));
  }

}

Role specific menus can be also registered:

import {MenuItem} from "kitcheningredients"
...
let menu = new MenuItem("ExampleItem", "ExampleItem", Example)

Menu.registerCommonMenu(menu); //Menu everyone can see
Menu.registerUnauthenticatedMenu(menu) //Menu unauthenticated users can see
Menu.registerAuthenticatedMenu(menu); //Menu authenticated users can see

Menu.registerMenuForRoleId("8cse873gbsbefu...", menu); //Menu only user with role id can see

//Attention! Multiple roles can have the same name
Menu.registerUnsafeMenuForRoleByName("Moderator", menu); //Menu only user with role which name is can see
let menu = new MenuItem(
  key, // string: define a unique string for the menu item
  label, //string: The displayed label
  destination, //[default null] FunctionComponent: which was registered
  items=null, //[default null] sub menu list
  command=null, //[default null] function:  will be called on selection
  content=null, //[default null] JSX.Element: If no sub menus given, content will be shown
  expanded=false, //[default false] boolean: if sub menus will be shown directly
  customIcon //[can be null] string or function (string: MaterialCommunity Icon name) (function: (menu, hasChildren, expanded, props.level))
);

During the registering of your screens/routes you can add a template. Typicly you will use the BaseTemplate.

export default class Project implements PluginInterface {
    registerRoutes() {
      Menu.registerRoute(Example, <TEMPLATE>, "Example", "example");
    }
}
  • BaseTemplate: Includes BaseNoPaddingTemplate and adds a BasePadding. Includes KeyboardAvoidingView which works inside Scrollviews.
    • Usecase: You want to show text or a standard component
    • BasePadding: Not a template but adds the base padding
  • BaseNoPaddingTemplate: Includes BaseNoPaddingTemplate and a Scrollview with breakpoint layout for different screen sizes. Includes KeyboardAvoidingView which works inside Scrollviews.
    • Usecase: You want to scroll and use your own padding added but dont want to rerender for every screen change
  • BaseNoScrollTemplate: Full width and height with basic title and drawer button without scrolling. Includes KeyboardAvoidingView which works inside Scrollviews.
    • Usecase: You want to implement a different scroll direction but want the drawer and title
  • EmptyTemplate: Nothing but the props: height and width to all children
    • Usecase: You want to show a fullscreen map and dont want the drawer or title

Remember you can use Route-Templates as your basic "Layout" or template for you content. If you want to get informations about the Layout of your screen you can use the following informations.

import {Layout} from "kitcheningredients"

export const MyFunctionComponent = (props) => {

    //boolean: true if using a small device
    let isSmallDevice = Layout.usesSmallDevice(); //triggers rerendering on change

    //number|string get the witdh of the content (e. G. "100%" or 700, ...)
    let contentWidth = Layout.useBaseTemplateContentWidth(); //triggers rerendering on change

    //get a dict with the layout sizes for different screen sizes
    let rawWidthValues = Layout.getRawWidthValues()
}

If you want variables depending on the screen size you can use useBreakpointValue. Get more informations at: https://docs.nativebase.io/3.4.x/use-breakpoint-value

Example from NativeBase, where you can get either a row or a column value depending on the screen size:

import {useBreakpointValue} from "native-base";

export const MyFunctionComponent = (props) => {
  const flexDir = useBreakpointValue({
    base: "column",
    lg: "row"
  });

}
import {NavigatorHelper} from "kitcheningredients";
import {Example} from "./screens/example/Example";

export const Tutorial = (props) => {

    // on button press
    function onPress(){
      // navigate to registered component
      NavigatorHelper.navigate(Example, newProps, resetHistory);

      // or navigate to a route
      NavigatorHelper.navigateToRouteName(routeName, newProps, resetHistory)
    }

}

TODO: navigateWithoutParams

TODO: toggleDrawer TODO: openDrawer TODO: closeDrawer TODO: goBack TODO: getRouteParams TODO: navigateHome

Auth

Authentication is done by the template. If you want to get the directus client, please read Server-API abouve.

In order to allow users self registration follow these steps:

  1. Directus => Settings => Roles & Permissions => Role Public allow to create Directus_users (expand at bottom) atleast email and password
  2. Optional Set desired default role (<YOUR_DEFAULT_ROLE_ID>): Directus => Settings => Roles & Permissions => Role Public => create Directus_users => Field Presets => {"role": "<YOUR_DEFAULT_ROLE_ID>"}
  3. Enable in your frontend app the button (in the index.js / index.web.js)
ConfigHolder.authConfig.mail.visible = true; //has to be enabled
ConfigHolder.authConfig.mail.registerVisible = true;

Synched States

Sometimes there is a need to synchronize states between different screens. This can be done by using the following functions. You will first need to register a state (see State Registration below). Then you can use the synchronized states (see Sync State usage).

First you have to register the state you want to synchronize. You have the following options:

  • Permanent: Save the state in the local storage
  • Temporal: Save the state in the session storage

In the Project.tsx file return the following classes you created:

...
	getSynchedStateKeysClass(){
		return SynchedStateKeys;
	}

	getStorageKeysClass(){
		return StorageKeys;
	}
...

An example of the above one class is shown below:

export class SynchedStateKeys {
    static exampleSynchedText = "SynchedStorage.exampleSynchedText"
}

Congrats, you are now able to use synched states accross your app.

In the Synched state only strings will be saved. If that is the case you can use useSynchedState otherwise you can use useSynchedJSONState.

  • useSynchedState
import {useSynchedState} from "kitcheningredients";

export const MyFunctionComponent = (props) => {
  const [myState, setMyState] = useSynchedState(SynchedStateKeys.exampleSynchedText);
}
  • useSynchedJSONState Beware that the state will be saved as JSON.stringify and therefore you cannot have circular references.
import {useSynchedJSONState} from "kitcheningredients";

export const MyFunctionComponent = (props) => {
  const [myJSONState, setMyJSONState] = useSynchedState(SynchedStateKeys.exampleSynchedJSON);
}

Components

Default Icons

import {Icon} from "kitcheningredients";
return (<Icon name={"account"} />) //Default MaterialIcons

Color and size

import {Icon} from "kitcheningredients";
return (<Icon name={"account"} color={"#FF0000"} size={"sm"} />) //Default MaterialIcons

More Icons

import {Ionicons} from "@expo/vector-icons";
import {Icon} from "kitcheningredients";
return (<Icon name={"account"} as={Ionicons} />)
import {TextWithIcon} from "kitcheningredients";
return (<TextWithIcon icon={"account"} content={"String"} />)

If you want to display an image from directus, like a mealImage or a user uploaded picture.

import {DirectusImage} from "kitcheningredients";

let myImageId = "sfsf6sef..."; //an image id you received
return (<DirectusImage assetId={myImageId} onPress={() => {console.log("Yeah!")}} />)
  • assetId: string;
    • The string of the immage id
  • alt?: string;
    • an alternative information if the image cant be shown
  • url?: string;
    • optional you can provide an url of an image from a different host like google,...
  • style?: any;
    • Styling object
  • showLoading?: boolean
    • default: true (shows a loading skeleton)
  • isPublic?: boolean
    • if the image resource is accessable for the public without authentication
  • onPress?: () => {}
    • A function which will be called on press

TODO: CrossLottie

You can use the KitchenSkeleton to show loading content. It will occupy the used space. More information at: https://docs.nativebase.io/3.4.x/skeleton#page-title

import {KitchenSkeleton} from "kitcheningredients";
return (<KitchenSkeleton flex={1} />)

You can use the Scrollview wrapper to show a gradient on the bottom, which indicates more content.

import {ScrollViewWithGradient} from "kitcheningredients";
return (
    <ScrollViewWithGradient>
      <Text>{"Lorem Ipsum long text or content"}</Text>
    </ScrollViewWithGradient>
);
  • hideGradient?: boolean
    • Shows or hides the gradient

If you want to show a actionsheet you can use the MyActionsheet. It pops up on top of the screen.

import {MyActionsheet} from "kitcheningredients";
const actionsheet = MyActionsheet.useActionsheet();
const params = {
  title: "Test",
  onAccept: () => {console.log("Accept")},
  ...
};
actionsheet.show(params);
  • title: string
  • acceptLabel?: string
    • default: "Accept"
  • cancelLabel?: string
    • default: "Cancel"
  • onAccept?: () => {}
    • A function which will be called on accept
  • onCancel?: () => {}
    • A function which will be called on cancel
  • renderCustomContent?: () => {}
    • A function which will be called to render the custom content

TODO: ThemedMarkdown TODO: DirectusMarkdown TODO: DirectusSingletonMarkdown

TODO: MyThemedBox

TODO: CustomFloaters

Created with

Builder Bob: https://github.com/callstack/react-native-builder-bob

Contributors

The FireboltCasters

12.0.40

8 months ago

11.0.36

10 months ago

12.0.7

10 months ago

12.0.8

10 months ago

12.0.9

10 months ago

12.0.3

10 months ago

12.0.4

10 months ago

12.0.5

10 months ago

12.0.6

10 months ago

12.0.1

10 months ago

12.0.2

10 months ago

12.0.39

8 months ago

12.0.38

8 months ago

12.0.35

9 months ago

12.0.34

9 months ago

12.0.37

9 months ago

12.0.36

9 months ago

12.0.31

9 months ago

12.0.30

9 months ago

12.0.33

9 months ago

12.0.32

9 months ago

12.0.28

9 months ago

12.0.27

9 months ago

12.0.29

9 months ago

12.0.24

9 months ago

12.0.23

9 months ago

12.0.26

9 months ago

12.0.25

9 months ago

12.0.20

9 months ago

12.0.22

9 months ago

12.0.21

9 months ago

11.0.48

10 months ago

11.0.49

10 months ago

12.0.17

10 months ago

12.0.16

10 months ago

12.0.19

10 months ago

12.0.18

10 months ago

12.0.13

10 months ago

12.0.12

10 months ago

12.0.15

10 months ago

12.0.14

10 months ago

12.0.11

10 months ago

12.0.10

10 months ago

11.0.42

10 months ago

11.0.43

10 months ago

11.0.41

10 months ago

11.0.46

10 months ago

11.0.47

10 months ago

11.0.44

10 months ago

11.0.45

10 months ago

11.0.10

1 year ago

11.0.13

1 year ago

11.0.11

1 year ago

11.0.12

1 year ago

11.0.31

1 year ago

11.0.32

1 year ago

11.0.30

1 year ago

11.0.35

1 year ago

11.0.33

1 year ago

11.0.34

1 year ago

11.0.28

1 year ago

11.0.29

1 year ago

11.0.26

1 year ago

11.0.27

1 year ago

11.0.21

1 year ago

11.0.24

1 year ago

11.0.25

1 year ago

11.0.22

1 year ago

11.0.23

1 year ago

10.2.14

1 year ago

10.2.13

1 year ago

11.0.6

1 year ago

11.0.7

1 year ago

11.0.4

1 year ago

11.0.5

1 year ago

11.0.8

1 year ago

11.0.9

1 year ago

11.0.2

1 year ago

11.0.3

1 year ago

11.0.1

1 year ago

10.2.3

1 year ago

10.2.4

1 year ago

10.2.5

1 year ago

10.2.6

1 year ago

10.2.7

1 year ago

10.2.8

1 year ago

10.2.9

1 year ago

10.2.1

1 year ago

10.2.2

1 year ago

10.2.12

1 year ago

10.2.10

1 year ago

10.2.11

1 year ago

10.1.5

1 year ago

10.1.6

1 year ago

10.1.7

1 year ago

10.1.8

1 year ago

0.2.63

1 year ago

0.2.62

1 year ago

0.2.61

2 years ago

0.2.60

2 years ago

0.2.59

2 years ago

0.2.58

2 years ago

0.2.57

2 years ago

0.2.56

2 years ago

0.2.55

2 years ago

0.2.52

2 years ago

0.2.51

2 years ago

0.2.50

2 years ago

0.2.54

2 years ago

0.2.53

2 years ago

0.2.41

2 years ago

0.2.40

2 years ago

0.2.49

2 years ago

0.2.48

2 years ago

0.2.47

2 years ago

0.2.46

2 years ago

0.2.45

2 years ago

0.2.44

2 years ago

0.2.43

2 years ago

0.2.42

2 years ago

0.2.39

2 years ago

0.2.30

2 years ago

0.2.38

2 years ago

0.2.37

2 years ago

0.2.36

2 years ago

0.2.35

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.29

2 years ago

0.2.27

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

2 years ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.13

2 years ago

0.2.12

2 years ago

0.2.11

2 years ago

0.2.10

2 years ago

0.1.139

2 years ago

0.1.136

2 years ago

0.1.135

2 years ago

0.1.138

2 years ago

0.1.137

2 years ago

0.1.134

2 years ago

0.1.147

2 years ago

0.1.146

2 years ago

0.1.149

2 years ago

0.1.148

2 years ago

0.1.143

2 years ago

0.1.142

2 years ago

0.1.145

2 years ago

0.1.144

2 years ago

0.1.141

2 years ago

0.1.158

2 years ago

0.1.157

2 years ago

0.1.159

2 years ago

0.1.154

2 years ago

0.1.153

2 years ago

0.1.156

2 years ago

0.1.155

2 years ago

0.1.150

2 years ago

0.1.152

2 years ago

0.1.151

2 years ago

0.1.169

2 years ago

0.1.168

2 years ago

0.1.165

2 years ago

0.1.164

2 years ago

0.1.167

2 years ago

0.1.166

2 years ago

0.1.161

2 years ago

0.1.160

2 years ago

0.1.163

2 years ago

0.1.162

2 years ago

0.1.170

2 years ago

0.1.172

2 years ago

0.1.171

2 years ago

0.1.173

2 years ago

0.2.1

2 years ago

0.2.28

2 years ago

0.2.7

2 years ago

0.2.6

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.2.5

2 years ago

0.2.4

2 years ago

0.1.52

2 years ago

0.1.53

2 years ago

0.1.54

2 years ago

0.1.55

2 years ago

0.1.56

2 years ago

0.1.57

2 years ago

0.1.58

2 years ago

0.1.59

2 years ago

0.1.50

2 years ago

0.1.51

2 years ago

0.1.118

2 years ago

0.1.117

2 years ago

0.1.119

2 years ago

0.1.114

2 years ago

0.1.113

2 years ago

0.1.116

2 years ago

0.1.115

2 years ago

0.1.110

2 years ago

0.1.49

2 years ago

0.1.112

2 years ago

0.1.111

2 years ago

0.1.41

2 years ago

0.1.43

2 years ago

0.1.46

2 years ago

0.1.47

2 years ago

0.1.48

2 years ago

0.1.40

2 years ago

0.1.129

2 years ago

0.1.128

2 years ago

0.1.125

2 years ago

0.1.124

2 years ago

0.1.127

2 years ago

0.1.126

2 years ago

0.1.121

2 years ago

0.1.38

2 years ago

0.1.120

2 years ago

0.1.39

2 years ago

0.1.123

2 years ago

0.1.30

2 years ago

0.1.31

2 years ago

0.1.32

2 years ago

0.1.33

2 years ago

0.1.34

2 years ago

0.1.35

2 years ago

0.1.36

2 years ago

0.1.37

2 years ago

0.1.132

2 years ago

0.1.27

2 years ago

0.1.131

2 years ago

0.1.28

2 years ago

0.1.29

2 years ago

0.1.133

2 years ago

0.1.130

2 years ago

0.1.20

2 years ago

0.1.21

2 years ago

0.1.22

2 years ago

0.1.26

2 years ago

0.1.16

2 years ago

0.1.17

2 years ago

0.1.18

2 years ago

0.1.19

2 years ago

0.1.96

2 years ago

0.1.97

2 years ago

0.1.10

2 years ago

0.1.99

2 years ago

0.1.90

2 years ago

0.1.91

2 years ago

0.1.92

2 years ago

0.1.95

2 years ago

0.1.85

2 years ago

0.1.86

2 years ago

0.1.87

2 years ago

0.1.88

2 years ago

0.1.89

2 years ago

0.1.80

2 years ago

0.1.81

2 years ago

0.1.82

2 years ago

0.1.83

2 years ago

0.1.84

2 years ago

0.1.8

2 years ago

0.0.26

2 years ago

0.1.7

2 years ago

0.1.9

2 years ago

0.1.4

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.74

2 years ago

0.1.75

2 years ago

0.1.76

2 years ago

0.1.77

2 years ago

0.0.21

2 years ago

0.1.78

2 years ago

0.1.79

2 years ago

0.1.70

2 years ago

0.1.71

2 years ago

0.1.72

2 years ago

0.1.73

2 years ago

0.0.16

2 years ago

0.1.63

2 years ago

0.1.64

2 years ago

0.1.66

2 years ago

0.1.67

2 years ago

0.1.68

2 years ago

0.1.69

2 years ago

0.0.13

2 years ago

0.1.60

2 years ago

0.1.61

2 years ago

0.1.62

2 years ago

0.1.107

2 years ago

0.1.106

2 years ago

0.1.109

2 years ago

0.1.108

2 years ago

0.1.103

2 years ago

0.1.102

2 years ago

0.1.105

2 years ago

0.1.104

2 years ago

0.1.101

2 years ago

0.1.100

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.6

2 years ago

0.0.2

2 years ago