-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1a0cb76
Showing
22 changed files
with
1,126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/build | ||
Carthage/ | ||
ti.calendar-iphone-*.zip | ||
/Cartfile.resolved | ||
.DS_Store | ||
/dist | ||
titanium-pencilkit.xcodeproj/project.xcworkspace/xcuserdata/*.xcuserdatad/UserInterfaceState.xcuserstate | ||
titanium-pencilkit.xcodeproj/xcuserdata/*.xcuserdatad/xcschemes/xcschememanagement.plist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Axway Titanium | ||
* Copyright (c) 2009-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#import <TitaniumKit/TitaniumKit.h> | ||
#import <PencilKit/PencilKit.h> | ||
|
||
API_AVAILABLE(ios(13.0)) | ||
@interface TiPencilkitCanvasView : TiUIView<PKCanvasViewDelegate, PKToolPickerObserver> | ||
|
||
@property(nonatomic, strong) PKCanvasView *canvasView; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/** | ||
* Axway Titanium | ||
* Copyright (c) 2009-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#import "TiPencilkitCanvasView.h" | ||
|
||
@implementation TiPencilkitCanvasView | ||
|
||
@synthesize canvasView = _canvasView; | ||
|
||
#pragma mark Private API's | ||
|
||
- (PKCanvasView *)canvasView | ||
{ | ||
if (_canvasView == nil) { | ||
_canvasView = [[PKCanvasView alloc] initWithFrame:self.bounds]; | ||
_canvasView.delegate = self; | ||
_canvasView.alwaysBounceVertical = YES; | ||
|
||
[self addSubview:_canvasView]; | ||
|
||
PKToolPicker *toolPicker = [PKToolPicker sharedToolPickerForWindow:TiApp.app.controller.view.window]; | ||
[toolPicker setVisible:YES forFirstResponder:_canvasView]; | ||
[toolPicker addObserver:_canvasView]; | ||
[toolPicker addObserver:self]; | ||
|
||
[self updateLayoutForToolPicker:toolPicker]; | ||
} | ||
|
||
return _canvasView; | ||
} | ||
|
||
- (void)updateLayoutForToolPicker:(PKToolPicker *)toolPicker | ||
{ | ||
CGRect obscuredFrame = [toolPicker frameObscuredInView:self]; | ||
if (CGRectIsNull(obscuredFrame)) { | ||
_canvasView.contentInset = UIEdgeInsetsZero; | ||
} else { | ||
_canvasView.contentInset = UIEdgeInsetsMake(0, 0, CGRectGetMaxX(self.bounds) - CGRectGetMinY(obscuredFrame), 0); | ||
} | ||
|
||
_canvasView.scrollIndicatorInsets = _canvasView.contentInset; | ||
} | ||
|
||
#pragma mark Public API's | ||
|
||
- (void)setAlwaysBounceVertical:(NSNumber *)alwaysBounceVertical | ||
{ | ||
[[self canvasView] setAlwaysBounceVertical:alwaysBounceVertical.boolValue]; | ||
} | ||
|
||
- (void)setAllowsFingerDrawing:(NSNumber *)allowsFingerDrawing | ||
{ | ||
[[self canvasView] setAllowsFingerDrawing:allowsFingerDrawing.boolValue]; | ||
} | ||
|
||
- (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds | ||
{ | ||
[TiUtils setView:[self canvasView] positionRect:bounds]; | ||
[super frameSizeChanged:frame bounds:bounds]; | ||
} | ||
|
||
#pragma mark PKCanvasViewDelegate | ||
|
||
- (void)canvasViewDidFinishRendering:(PKCanvasView *)canvasView | ||
{ | ||
[self.proxy fireEvent:@"finishedRendering"]; | ||
} | ||
|
||
- (void)canvasViewDidBeginUsingTool:(PKCanvasView *)canvasView | ||
{ | ||
[self.proxy fireEvent:@"begin"]; | ||
} | ||
|
||
- (void)canvasViewDrawingDidChange:(PKCanvasView *)canvasView | ||
{ | ||
[self.proxy fireEvent:@"change"]; | ||
} | ||
|
||
- (void)canvasViewDidEndUsingTool:(PKCanvasView *)canvasView | ||
{ | ||
[self.proxy fireEvent:@"end"]; | ||
} | ||
|
||
#pragma mark PKToolPickerObserver | ||
|
||
- (void)toolPickerVisibilityDidChange:(PKToolPicker *)toolPicker | ||
{ | ||
[self.proxy fireEvent:@"toolPicker:visibilityDidChange" withObject:@{ @"isVisible": @(toolPicker.isVisible) }]; | ||
[self updateLayoutForToolPicker:toolPicker]; | ||
} | ||
|
||
- (void)toolPickerSelectedToolDidChange:(PKToolPicker *)toolPicker | ||
{ | ||
[self.proxy fireEvent:@"toolPicker:selectedToolDidChange"]; | ||
} | ||
|
||
- (void)toolPickerIsRulerActiveDidChange:(PKToolPicker *)toolPicker | ||
{ | ||
[self.proxy fireEvent:@"toolPicker:isRulerActiveDidChange" withObject:@{ @"rulerActive": @(toolPicker.rulerActive) }]; | ||
} | ||
|
||
- (void)toolPickerFramesObscuredDidChange:(PKToolPicker *)toolPicker | ||
{ | ||
[self.proxy fireEvent:@"toolPicker:framesObscuredDidChange"]; | ||
[self updateLayoutForToolPicker:toolPicker]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Axway Titanium | ||
* Copyright (c) 2009-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#import <TitaniumKit/TitaniumKit.h> | ||
|
||
API_AVAILABLE(ios(13.0)) | ||
@interface TiPencilkitCanvasViewProxy : TiViewProxy | ||
|
||
- (void)setDrawing:(TiBlob *)drawingBlob; | ||
|
||
- (void)focus:(id)unused; | ||
|
||
- (void)exportDrawingData:(id)callback; | ||
|
||
- (void)exportDrawingAsImage:(id)args; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* Axway Titanium | ||
* Copyright (c) 2009-present by Axway Appcelerator. All Rights Reserved. | ||
* Licensed under the terms of the Apache Public License | ||
* Please see the LICENSE included with this distribution for details. | ||
*/ | ||
|
||
#import "TiPencilkitCanvasView.h" | ||
#import "TiPencilkitCanvasViewProxy.h" | ||
#import <PencilKit/PencilKit.h> | ||
|
||
@implementation TiPencilkitCanvasViewProxy | ||
|
||
#pragma mark Private API's | ||
|
||
- (TiPencilkitCanvasView *)canvasView | ||
{ | ||
return (TiPencilkitCanvasView *) self.view; | ||
} | ||
|
||
#pragma mark Public API's | ||
|
||
- (void)setDrawing:(TiBlob *)drawingBlob | ||
{ | ||
if (drawingBlob == nil) { | ||
[[[self canvasView] canvasView] setDrawing:[PKDrawing new]]; | ||
return; | ||
} | ||
|
||
NSError *error = nil; | ||
PKDrawing *drawing = [[PKDrawing alloc] initWithData:drawingBlob.data error:&error]; | ||
|
||
if (error != nil) { | ||
NSLog(@"[ERROR] Cannot import drawing: %@", error.localizedDescription); | ||
return; | ||
} | ||
|
||
[[[self canvasView] canvasView] setDrawing:drawing]; | ||
} | ||
|
||
- (void)focus:(id)unused | ||
{ | ||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ | ||
[[[self canvasView] canvasView] becomeFirstResponder]; | ||
}); | ||
} | ||
|
||
- (void)exportDrawingData:(id)callback | ||
{ | ||
ENSURE_SINGLE_ARG(callback, KrollCallback); | ||
|
||
PKDrawing *drawing = [[[self canvasView] canvasView] drawing]; | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
NSData *dataRepresentation = [drawing dataRepresentation]; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^(){ | ||
[callback call:@[@{ @"data": [[TiBlob alloc] initWithData:dataRepresentation mimetype:(NSString *) PKAppleDrawingTypeIdentifier] }] thisObject:self]; | ||
}); | ||
}); | ||
} | ||
|
||
- (void)exportDrawingAsImage:(id)args | ||
{ | ||
ENSURE_SINGLE_ARG(args, NSDictionary); | ||
|
||
KrollCallback *callback = (KrollCallback *)args[@"callback"]; | ||
PKDrawing *drawing = [[[self canvasView] canvasView] drawing]; | ||
|
||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ | ||
UIImage *image = [drawing imageFromRect:drawing.bounds scale:UIScreen.mainScreen.scale]; | ||
|
||
dispatch_async(dispatch_get_main_queue(), ^(){ | ||
[callback call:@[@{ @"image": [[TiBlob alloc] initWithImage:image] }] thisObject:self]; | ||
}); | ||
}); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* titanium-pencilkit | ||
* | ||
* Created by Your Name | ||
* Copyright (c) 2019 Your Company. All rights reserved. | ||
*/ | ||
|
||
#import "TiModule.h" | ||
|
||
@interface TiPencilkitModule : TiModule { | ||
|
||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* titanium-pencilkit | ||
* | ||
* Created by Your Name | ||
* Copyright (c) 2019 Your Company. All rights reserved. | ||
*/ | ||
|
||
#import "TiPencilkitModule.h" | ||
#import "TiBase.h" | ||
#import "TiHost.h" | ||
#import "TiUtils.h" | ||
|
||
@implementation TiPencilkitModule | ||
|
||
#pragma mark Internal | ||
|
||
// This is generated for your module, please do not change it | ||
- (id)moduleGUID | ||
{ | ||
return @"297369cd-a62e-4740-8993-8201ec43b5fd"; | ||
} | ||
|
||
// This is generated for your module, please do not change it | ||
- (NSString *)moduleId | ||
{ | ||
return @"ti.pencilkit"; | ||
} | ||
|
||
#pragma mark Lifecycle | ||
|
||
- (void)startup | ||
{ | ||
// This method is called when the module is first loaded | ||
// You *must* call the superclass | ||
[super startup]; | ||
DebugLog(@"[DEBUG] %@ loaded", self); | ||
} | ||
|
||
#pragma Public APIs | ||
|
||
- (NSString *)example:(id)args | ||
{ | ||
// Example method. | ||
// Call with "MyModule.example(args)" | ||
return @"hello world"; | ||
} | ||
|
||
- (NSString *)exampleProp | ||
{ | ||
// Example property getter. | ||
// Call with "MyModule.exampleProp" or "MyModule.getExampleProp()" | ||
return @"Titanium rocks!"; | ||
} | ||
|
||
- (void)setExampleProp:(id)value | ||
{ | ||
// Example property setter. | ||
// Call with "MyModule.exampleProp = 'newValue'" or "MyModule.setExampleProp('newValue')" | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* This is a generated file. Do not edit or your changes will be lost | ||
*/ | ||
|
||
@interface TiPencilkitModuleAssets : NSObject { | ||
|
||
} | ||
|
||
- (NSData *)moduleAsset; | ||
- (NSData *)resolveModuleAsset:(NSString*)path; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* This is a generated file. Do not edit or your changes will be lost | ||
*/ | ||
#import "TiPencilkitModuleAssets.h" | ||
|
||
extern NSData* filterDataInRange(NSData* thedata, NSRange range); | ||
|
||
@implementation TiPencilkitModuleAssets | ||
|
||
- (NSData *)moduleAsset | ||
{ | ||
|
||
|
||
return nil; | ||
} | ||
|
||
- (NSData *)resolveModuleAsset:(NSString *)path | ||
{ | ||
|
||
|
||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UNLICENSED |
Oops, something went wrong.