Giter Club home page Giter Club logo

react-native-pencil-kit's Introduction


React Native Pencil Kit

NPM downloads NPM version License

iOS Easy & Robust Pencil Kit Porting

React Native Pencil Kit is a full API support iOS PencilKit framework porting.

preview

Getting Started

yarn add react-native-pencil-kit

Link PencilKit.framework in the Xcode application project settings

xcode

With Fabric, we should access c++ functions and we should use objective-c++. This prevents us from Apple SDK framework module importing and we cannot link PencilKit automatically at now. If you are using use_frameworks!(dynamic linking), this configuration is maybe not required.

Usage

import PencilKitView, { type PencilKitRef, type PencilKitTool } from 'react-native-pencil-kit';

<PencilKitView style={{ flex: 1 }} />

Note

You can explore full example! Full Example

Props

Props Description Default
alwaysBounceVertical A Boolean value that determines whether bouncing always occurs when vertical scrolling reaches the end of the content. true
alwaysBounceHorizontal A Boolean value that determines whether bouncing always occurs when horizontal scrolling reaches the end of the content view. true
isRulerActive A Boolean value that indicates whether a ruler view is visible on the canvas. false
drawingPolicy The policy that controls the types of touches allowed when drawing on the canvas. This properties can be applied from iOS 14.0 default
backgroundColor The canvas background color none
isOpaque Whether the canvas is opaque true
toolPickerVisibilityDidChange Tells the delegate that the tool picker UI changed visibility.
toolPickerIsRulerActiveDidChange Tells the delegate that the ruler active state was changed by the user.
toolPickerFramesObscuredDidChange Tells the delegate that the frames the tool picker obscures changed.
toolPickerSelectedToolDidChange Tells the delegate that the selected tool was changed by the user.
canvasViewDidBeginUsingTool Called when the user starts using a tool, eg. selecting, drawing, or erasing.
canvasViewDidEndUsingTool Called when the user stops using a tool, eg. selecting, drawing, or erasing.
canvasViewDrawingDidChange Called after the drawing on the canvas did change.
canvasViewDidFinishRendering Called after setting drawing when the entire drawing is rendered and visible.

Commands

Method Description Etc
clear(): void Clear canvas
showToolPicker(): void Show Palette
hideToolPicker(): void Hide Palette
redo(): void Redo last drawing action
undo(): void Undo last drawing action
saveDrawing(path: string): Promise<string> Save drawing data into file system, return base64 data
getBase64Data(): Promise<string> Get current drawing data as base64 string form
getBase64PngData(options: { scale?: number }): Promise<string> Get current drawing data as base64 png form scale = 0 means use default UIScreen.main.scale
getBase64JpegData(options: { scale?: number; compression?: number }): Promise<string> Get current drawing data as base64 jpeg form scale = 0 means use default UIScreen.main.scale. default compression is 0.93
loadDrawing(path: string): Promise<void> Load drawing data from file system
loadBase64Data(base64: string): Promise<void> Load base64 drawing data into canvas Use base64 get from getBase64Data()
setTool(params: { toolType: PencilKitTool; width?: number; color?: ColorValue }): void Set PencilKitTool type with width and color

Tools

- pen
- pencil
- marker
- monoline // ios 17
- fountainPen // ios 17
- watercolor // ios 17
- crayon // ios 17
- eraserVector // width is supported from 16.4
- eraserBitmap // width is supported from 16.4
- eraserFixedWidthBitmap // ios 16.4

Utils

Use PencilKitUtil for using utilty functions.

  • getAvailableTools(): string[]
  • isPencilKitAvailable(): boolean

Troubleshooting

  • Pencilkit is not rendered
    • This package supports only equal or greater than 14.0 version.
    • This package supports only Fabric.

Contributing

License


Built and maintained by MJ Studio.

react-native-pencil-kit's People

Contributors

mym0404 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

react-native-pencil-kit's Issues

Issue building with expo

I tried to install react-native-pencil-kit with expo, and i'm running into an issue here:

CommandError: Failed to build iOS project. "xcodebuild" exited with error code 65.

โ€บ Compiling react-native-pencil-kit Pods/RNPencilKit ยป RNPencilKitUtil.mm

โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:19:4)

  17 | RCT_EXPORT_MODULE()
  18 | 
> 19 | - (RNPencilKit*)getView:(double)viewId {
     |    ^ expected a type
  20 |   return (RNPencilKit*)[self.bridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewId]];
  21 | }
  22 | 


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:20:11)

  18 | 
  19 | - (RNPencilKit*)getView:(double)viewId {
> 20 |   return (RNPencilKit*)[self.bridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewId]];
     |           ^ use of undeclared identifier 'RNPencilKit'
  21 | }
  22 | 
  23 | - (void)doReject:(RCTPromiseRejectBlock)reject name:(NSString*)name {


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:20:23)

  18 | 
  19 | - (RNPencilKit*)getView:(double)viewId {
> 20 |   return (RNPencilKit*)[self.bridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewId]];
     |                       ^ expected expression
  21 | }
  22 | 
  23 | - (void)doReject:(RCTPromiseRejectBlock)reject name:(NSString*)name {


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:20:25)

  18 | 
  19 | - (RNPencilKit*)getView:(double)viewId {
> 20 |   return (RNPencilKit*)[self.bridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewId]];
     |                         ^ missing '[' at start of message send expression
  21 | }
  22 | 
  23 | - (void)doReject:(RCTPromiseRejectBlock)reject name:(NSString*)name {


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:20:98)

  18 | 
  19 | - (RNPencilKit*)getView:(double)viewId {
> 20 |   return (RNPencilKit*)[self.bridge.uiManager viewForReactTag:[NSNumber numberWithDouble:viewId]];
     |                                                                                                  ^ expected ']'
  21 | }
  22 | 
  23 | - (void)doReject:(RCTPromiseRejectBlock)reject name:(NSString*)name {


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:32:5)

  30 |                reject:(RCTPromiseRejectBlock)reject {
  31 |   RCTExecuteOnMainQueue(^{
> 32 |     RNPencilKit* view = [self getView:viewId];
     |     ^ unknown type name 'RNPencilKit'
  33 |     NSString* ret = [view getBase64Data];
  34 |     if (ret) {
  35 |       resolve(ret);


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:47:5)

  45 |                   reject:(RCTPromiseRejectBlock)reject {
  46 |   RCTExecuteOnMainQueue(^{
> 47 |     RNPencilKit* view = [self getView:viewId];
     |     ^ unknown type name 'RNPencilKit'
  48 |     NSString* ret = [view getBase64PngData:scale];
  49 |     if (ret) {
  50 |       resolve(ret);


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:63:5)

  61 |                    reject:(RCTPromiseRejectBlock)reject {
  62 |   RCTExecuteOnMainQueue(^{
> 63 |     RNPencilKit* view = [self getView:viewId];
     |     ^ unknown type name 'RNPencilKit'
  64 |     NSString* ret = [view getBase64JpegData:scale compression:compression];
  65 |     if (ret) {
  66 |       resolve(ret);


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:78:5)

  76 |              reject:(RCTPromiseRejectBlock)reject {
  77 |   RCTExecuteOnMainQueue(^{
> 78 |     RNPencilKit* view = [self getView:viewId];
     |     ^ unknown type name 'RNPencilKit'
  79 |     NSString* ret = [view saveDrawing:path];
  80 |     if (ret) {
  81 |       resolve(ret);


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:93:5)

  91 |              reject:(RCTPromiseRejectBlock)reject {
  92 |   RCTExecuteOnMainQueue(^{
> 93 |     RNPencilKit* view = [self getView:viewId];
     |     ^ unknown type name 'RNPencilKit'
  94 |     BOOL ret = [view loadDrawing:path];
  95 |     if (ret) {
  96 |       resolve(@"");


โŒ  (node_modules/react-native-pencil-kit/ios/RNPencilKitUtil.mm:108:5)

  106 |                 reject:(RCTPromiseRejectBlock)reject {
  107 |   RCTExecuteOnMainQueue(^{
> 108 |     RNPencilKit* view = [self getView:viewId];
      |     ^ unknown type name 'RNPencilKit'
  109 |     BOOL ret = [view loadBase64Data:base64];
  110 |     if (ret) {
  111 |       resolve(@"");

โ€บ Compiling react-native-pencil-kit Pods/RNPencilKit ยป RNPencilKit.mm

If you're not interested in expo support, fair enough. I just thought it might be worth sharing my experience in case expo was on your radar at all.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.