Skip to content

Commit

Permalink
feat: done
Browse files Browse the repository at this point in the history
  • Loading branch information
mym0404 committed May 3, 2024
1 parent 9414f3b commit a553c93
Show file tree
Hide file tree
Showing 18 changed files with 1,132 additions and 84 deletions.
4 changes: 2 additions & 2 deletions react-native-pencil-kit.podspec → RNPencilKit.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = "react-native-pencil-kit"
s.name = "RNPencilKit"
s.version = package["version"]
s.summary = package["description"]
s.homepage = package["homepage"]
s.license = package["license"]
s.authors = package["author"]

s.platforms = { :ios => min_ios_version_supported }
s.platforms = { :ios => '14.0' }
s.source = { :git => "https://github.com/mym0404/react-native-pencil-kit.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}"
Expand Down
24 changes: 23 additions & 1 deletion example/ios/PencilKitExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2D8473532BE51B21002D299C /* noop.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2D8473522BE51B21002D299C /* noop.swift */; };
2D8473582BE51E3E002D299C /* libPods-PencilKitExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D8473572BE51E3E002D299C /* libPods-PencilKitExample.a */; };
2D8473592BE51E96002D299C /* PencilKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2D8473552BE51D03002D299C /* PencilKit.framework */; };
7699B88040F8A987B510C191 /* libPods-PencilKitExample-PencilKitExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-PencilKitExample-PencilKitExampleTests.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
Expand All @@ -38,6 +41,10 @@
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = PencilKitExample/main.m; sourceTree = "<group>"; };
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = PencilKitExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
19F6CBCC0A4E27FBF8BF4A61 /* libPods-PencilKitExample-PencilKitExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-PencilKitExample-PencilKitExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
2D8473512BE51B21002D299C /* PencilKitExample-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PencilKitExample-Bridging-Header.h"; sourceTree = "<group>"; };
2D8473522BE51B21002D299C /* noop.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = noop.swift; sourceTree = "<group>"; };
2D8473552BE51D03002D299C /* PencilKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PencilKit.framework; path = System/Library/Frameworks/PencilKit.framework; sourceTree = SDKROOT; };
2D8473572BE51E3E002D299C /* libPods-PencilKitExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = "libPods-PencilKitExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3B4392A12AC88292D35C810B /* Pods-PencilKitExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PencilKitExample.debug.xcconfig"; path = "Target Support Files/Pods-PencilKitExample/Pods-PencilKitExample.debug.xcconfig"; sourceTree = "<group>"; };
5709B34CF0A7D63546082F79 /* Pods-PencilKitExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PencilKitExample.release.xcconfig"; path = "Target Support Files/Pods-PencilKitExample/Pods-PencilKitExample.release.xcconfig"; sourceTree = "<group>"; };
5B7EB9410499542E8C5724F5 /* Pods-PencilKitExample-PencilKitExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PencilKitExample-PencilKitExampleTests.debug.xcconfig"; path = "Target Support Files/Pods-PencilKitExample-PencilKitExampleTests/Pods-PencilKitExample-PencilKitExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand All @@ -60,7 +67,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
2D8473582BE51E3E002D299C /* libPods-PencilKitExample.a in Frameworks */,
0C80B921A6F3F58F76C31292 /* libPods-PencilKitExample.a in Frameworks */,
2D8473592BE51E96002D299C /* PencilKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -94,13 +103,17 @@
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */,
13B07FB71A68108700A75B9A /* main.m */,
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */,
2D8473522BE51B21002D299C /* noop.swift */,
2D8473512BE51B21002D299C /* PencilKitExample-Bridging-Header.h */,
);
name = PencilKitExample;
sourceTree = "<group>";
};
2D16E6871FA4F8E400B85C8A /* Frameworks */ = {
isa = PBXGroup;
children = (
2D8473572BE51E3E002D299C /* libPods-PencilKitExample.a */,
2D8473552BE51D03002D299C /* PencilKit.framework */,
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
5DCACB8F33CDC322A6C60F78 /* libPods-PencilKitExample.a */,
19F6CBCC0A4E27FBF8BF4A61 /* libPods-PencilKitExample-PencilKitExampleTests.a */,
Expand Down Expand Up @@ -208,7 +221,7 @@
TestTargetID = 13B07F861A680F5B00A75B9A;
};
13B07F861A680F5B00A75B9A = {
LastSwiftMigration = 1120;
LastSwiftMigration = 1530;
};
};
};
Expand Down Expand Up @@ -395,6 +408,7 @@
buildActionMask = 2147483647;
files = (
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */,
2D8473532BE51B21002D299C /* noop.swift in Sources */,
13B07FC11A68108700A75B9A /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -414,6 +428,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-PencilKitExample-PencilKitExampleTests.debug.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -441,6 +456,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 89C6BE57DB24E9ADA2F236DE /* Pods-PencilKitExample-PencilKitExampleTests.release.xcconfig */;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
BUNDLE_LOADER = "$(TEST_HOST)";
COPY_PHASE_STRIP = NO;
INFOPLIST_FILE = PencilKitExampleTests/Info.plist;
Expand Down Expand Up @@ -470,6 +486,8 @@
CURRENT_PROJECT_VERSION = 1;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = PencilKitExample/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -482,6 +500,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = PencilKitExample;
SWIFT_OBJC_BRIDGING_HEADER = "PencilKitExample-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -496,6 +515,8 @@
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
INFOPLIST_FILE = PencilKitExample/Info.plist;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.developer-tools";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -508,6 +529,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = PencilKitExample;
SWIFT_OBJC_BRIDGING_HEADER = "PencilKitExample-Bridging-Header.h";
SWIFT_VERSION = 5.0;
VERSIONING_SYSTEM = "apple-generic";
};
Expand Down
75 changes: 50 additions & 25 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
PODS:
- boost (1.83.0)
- DoubleConversion (1.1.6)
- dr-pogodin-react-native-fs (2.24.6):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- FBLazyVector (0.74.0)
- fmt (9.1.0)
- glog (0.3.5)
Expand Down Expand Up @@ -935,27 +956,6 @@ PODS:
- React-Mapbuffer (0.74.0):
- glog
- React-debug
- react-native-pencil-kit (0.1.0-alpha.2):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- React-nativeconfig (0.74.0)
- React-NativeModulesApple (0.74.0):
- glog
Expand Down Expand Up @@ -1184,12 +1184,34 @@ PODS:
- React-logger (= 0.74.0)
- React-perflogger (= 0.74.0)
- React-utils (= 0.74.0)
- RNPencilKit (0.1.0-alpha.2):
- DoubleConversion
- glog
- hermes-engine
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- SocketRocket (0.7.0)
- Yoga (0.0.0)

DEPENDENCIES:
- boost (from `../node_modules/react-native/third-party-podspecs/boost.podspec`)
- DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
- "dr-pogodin-react-native-fs (from `../node_modules/@dr.pogodin/react-native-fs`)"
- FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`)
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
Expand Down Expand Up @@ -1220,7 +1242,6 @@ DEPENDENCIES:
- React-jsitracing (from `../node_modules/react-native/ReactCommon/hermes/executor/`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- react-native-pencil-kit (from `../..`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
Expand All @@ -1244,6 +1265,7 @@ DEPENDENCIES:
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- RNPencilKit (from `../..`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand All @@ -1255,6 +1277,8 @@ EXTERNAL SOURCES:
:podspec: "../node_modules/react-native/third-party-podspecs/boost.podspec"
DoubleConversion:
:podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
dr-pogodin-react-native-fs:
:path: "../node_modules/@dr.pogodin/react-native-fs"
FBLazyVector:
:path: "../node_modules/react-native/Libraries/FBLazyVector"
fmt:
Expand Down Expand Up @@ -1312,8 +1336,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/logger"
React-Mapbuffer:
:path: "../node_modules/react-native/ReactCommon"
react-native-pencil-kit:
:path: "../.."
React-nativeconfig:
:path: "../node_modules/react-native/ReactCommon"
React-NativeModulesApple:
Expand Down Expand Up @@ -1360,12 +1382,15 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/react/utils"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNPencilKit:
:path: "../.."
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
dr-pogodin-react-native-fs: 7e0b92aa0ea441ed86247cec1686e6682378afe0
FBLazyVector: 026c8f4ae67b06e088ae01baa2271ef8a26c0e8c
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: c5d68082e772fa1c511173d6b30a9de2c05a69a2
Expand Down Expand Up @@ -1394,7 +1419,6 @@ SPEC CHECKSUMS:
React-jsitracing: 36a2bbc272300313653d980de5ab700ec86c534a
React-logger: 03f2f7b955cfe24593a2b8c9705c23e142d1ad24
React-Mapbuffer: 5e05d78fe6505f4a054b86f415733d4ad02dd314
react-native-pencil-kit: 5c143168cadf085370cc469a732d357da8aa74a1
React-nativeconfig: 951ec32f632e81cbd7d40aebb3211313251c092e
React-NativeModulesApple: 0b3a42ca90069119ef79d8b2327d01441d71abd4
React-perflogger: 271f1111779fef70f9502d1d38da5132e5585230
Expand All @@ -1418,6 +1442,7 @@ SPEC CHECKSUMS:
React-runtimescheduler: 7fe561d179b97cecd0c2bec0bbd08f9fd8581c26
React-utils: f013537c3371270d2095bff1d594d00d4bc9261b
ReactCommon: 2cde697fd80bd31da1d6448d25a5803088585219
RNPencilKit: f290fbdcadd41189b33df9d6ba300b2fe7d272c8
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 56f906bf6c11c931588191dde1229fd3e4e3d557

Expand Down
8 changes: 8 additions & 0 deletions example/ios/noop.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// noop.swift
// PencilKitExample
//
// Created by mj on 5/3/24.
//

import Foundation
1 change: 1 addition & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build:ios": "cd ios && xcodebuild -workspace PencilKitExample.xcworkspace -scheme PencilKitExample -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO"
},
"dependencies": {
"@dr.pogodin/react-native-fs": "^2.24.6",
"react": "18.2.0",
"react-native": "0.74.0"
},
Expand Down
73 changes: 57 additions & 16 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,64 @@
import { StyleSheet, View } from 'react-native';
import PencilKitView from 'react-native-pencil-kit';
import { useRef } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import PencilKitView, { type PencilKitRef } from 'react-native-pencil-kit';
import { DocumentDirectoryPath } from '@dr.pogodin/react-native-fs';

export default function App() {
const ref = useRef<PencilKitRef>(null);

const path = `${DocumentDirectoryPath}/drawing.dat`;

return (
<View style={styles.container}>
<PencilKitView style={styles.box} />
<View style={{ width: '100%', height: '100%' }}>
<PencilKitView
ref={ref}
style={{ flex: 1 }}
alwaysBounceVertical={false}
alwaysBounceHorizontal={false}
drawingPolicy={'anyinput'}
backgroundColor={'blue'}
/>
<View
style={{
height: 300,
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
gap: 4,
padding: 8,
}}
>
<Btn onPress={() => ref.current?.showToolPicker()} text={'show'} />
<Btn onPress={() => ref.current?.hideToolPicker()} text={'hide'} />
<Btn onPress={() => ref.current?.clear()} text={'clear'} />
<Btn onPress={() => ref.current?.undo()} text={'undo'} />
<Btn onPress={() => ref.current?.redo()} text={'redo'} />
<Btn onPress={() => ref.current?.saveDrawing(path)} text={'save'} />
<Btn onPress={() => ref.current?.loadDrawing(path)} text={'load'} />
<Btn onPress={() => ref.current?.getBase64Data()} text={'get base64'} />
<Btn onPress={() => ref.current?.loadBase64Data('')} text={'load base64'} />
<Btn
onPress={() =>
ref.current?.setTool({
toolType: 'pen',
width: 2,
color: 'red',
})
}
text={'pen'}
/>
</View>
</View>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
});
const Btn = ({ onPress, text }: { onPress: () => void; text: string }) => {
return (
<TouchableOpacity
onPress={onPress}
style={{ padding: 8, backgroundColor: 'black', borderRadius: 4 }}
>
<Text style={{ color: 'white', fontWeight: 'bold' }}>{text.toUpperCase()}</Text>
</TouchableOpacity>
);
};
3 changes: 3 additions & 0 deletions ios/RNPencilKit.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// This guard prevent this file to be compiled in the old architecture.
#ifdef RCT_NEW_ARCH_ENABLED
#import "RNPencilKitUtilFunction.h"
#import <PencilKit/PencilKit.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTViewComponentView.h>
#import <UIKit/UIKit.h>

Expand Down
Loading

0 comments on commit a553c93

Please sign in to comment.