Skip to content

Commit

Permalink
Merge pull request #6 from stephenfeather/MOD-2070-deux
Browse files Browse the repository at this point in the history
[MOD-2070] iOS: Add support for touchstart, touchend, touchcancel, touchmove
  • Loading branch information
hansemannn authored Dec 21, 2016
2 parents 23526e7 + db0592f commit 5f3da9d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 25 deletions.
20 changes: 20 additions & 0 deletions ios/Classes/TiPaintPaintView.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,24 @@ - (void)clear:(id)args
}
}

#pragma mark Event Handlers
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self.proxy fireEvent:@"touchend"];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.proxy fireEvent:@"touchstart"];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.proxy fireEvent:@"touchmove"];
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.proxy fireEvent:@"touchcancel"];
}

@end
2 changes: 2 additions & 0 deletions ios/documentation/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Change Log
<pre>
v1.4.1 Added support for touchstart, touchend, touchcancel, touchmove [MOD-2070]

v1.4.0 Updated project with 64bit binary support [TIMOB-18092]

v1.3 Rewrote rendering algorithm to allow for a number of enhancements:
Expand Down
20 changes: 19 additions & 1 deletion ios/documentation/paintView.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,22 @@ Controls if the strokes are in "erase mode" -- that is, any existing paint will

### image[string]

Loads an image (by its URL) directly in to the paint view so that it can be drawn on and erased.
Loads an image (by its URL) directly in to the paint view so that it can be drawn on and erased.

## Events

### touchcancel

Fired when a touch event is interrupted by the device.

### touchend

Fired when a touch event is completed.

### touchmove

Fired as soon as the device detects movement of a touch.

### touchstart

Fired as soon as the device detects a touch gesture.
116 changes: 94 additions & 22 deletions ios/example/app.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,120 @@
var Paint = require('ti.paint');

var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var win = Ti.UI.createWindow({
backgroundColor: '#fff'
});
var paintView = Paint.createPaintView({
top:0, right:0, bottom:80, left:0,
top: 0,
right: 0,
bottom: 80,
left: 0,
// strokeWidth (float), strokeColor (string), strokeAlpha (int, 0-255)
strokeColor:'#0f0', strokeAlpha:255, strokeWidth:10,
eraseMode:false
strokeColor: '#0f0',
strokeAlpha: 255,
strokeWidth: 10,
eraseMode: false
});
win.add(paintView);

var buttonStrokeWidth = Ti.UI.createButton({ left:10, bottom:10, right:10, height:30, title:'Decrease Stroke Width' });
var buttonStrokeWidth = Ti.UI.createButton({
left: 10,
bottom: 10,
right: 10,
height: 30,
title: 'Decrease Stroke Width'
});
buttonStrokeWidth.addEventListener('click', function(e) {
paintView.strokeWidth = (paintView.strokeWidth === 10) ? 5 : 10;
e.source.title = (paintView.strokeWidth === 10) ? 'Decrease Stroke Width' : 'Increase Stroke Width';
paintView.strokeWidth = (paintView.strokeWidth === 10) ? 5 : 10;
e.source.title = (paintView.strokeWidth === 10) ? 'Decrease Stroke Width' : 'Increase Stroke Width';
});
win.add(buttonStrokeWidth);

var buttonStrokeColorRed = Ti.UI.createButton({ bottom:100, left:10, width:75, height:30, title:'Red' });
buttonStrokeColorRed.addEventListener('click', function() { paintView.strokeColor = 'red'; });
var buttonStrokeColorGreen = Ti.UI.createButton({ bottom:70, left:10, width:75, height:30, title:'Green' });
buttonStrokeColorGreen.addEventListener('click', function() { paintView.strokeColor = '#0f0'; });
var buttonStrokeColorBlue = Ti.UI.createButton({ bottom:40, left:10, width:75, height:30, title:'Blue' });
buttonStrokeColorBlue.addEventListener('click', function() { paintView.strokeColor = '#0000ff'; });
var buttonStrokeColorRed = Ti.UI.createButton({
bottom: 100,
left: 10,
width: 75,
height: 30,
title: 'Red'
});
buttonStrokeColorRed.addEventListener('click', function() {
paintView.strokeColor = 'red';
});
var buttonStrokeColorGreen = Ti.UI.createButton({
bottom: 70,
left: 10,
width: 75,
height: 30,
title: 'Green'
});
buttonStrokeColorGreen.addEventListener('click', function() {
paintView.strokeColor = '#0f0';
});
var buttonStrokeColorBlue = Ti.UI.createButton({
bottom: 40,
left: 10,
width: 75,
height: 30,
title: 'Blue'
});
buttonStrokeColorBlue.addEventListener('click', function() {
paintView.strokeColor = '#0000ff';
});
win.add(buttonStrokeColorRed);
win.add(buttonStrokeColorGreen);
win.add(buttonStrokeColorBlue);

var clear = Ti.UI.createButton({ bottom:40, left:100, width:75, height:30, title:'Clear' });
clear.addEventListener('click', function() { paintView.clear(); });
var clear = Ti.UI.createButton({
bottom: 40,
left: 100,
width: 75,
height: 30,
title: 'Clear'
});
clear.addEventListener('click', function() {
paintView.clear();
});
win.add(clear);

var buttonStrokeAlpha = Ti.UI.createButton({ bottom:70, right:10, width:100, height:30, title:'Alpha : 100%' });
var buttonStrokeAlpha = Ti.UI.createButton({
bottom: 70,
right: 10,
width: 100,
height: 30,
title: 'Alpha : 100%'
});
buttonStrokeAlpha.addEventListener('click', function(e) {
paintView.strokeAlpha = (paintView.strokeAlpha === 255) ? 127 : 255;
e.source.title = (paintView.strokeAlpha === 255) ? 'Alpha : 100%' : 'Alpha : 50%';
paintView.strokeAlpha = (paintView.strokeAlpha === 255) ? 127 : 255;
e.source.title = (paintView.strokeAlpha === 255) ? 'Alpha : 100%' : 'Alpha : 50%';
});
win.add(buttonStrokeAlpha);

var buttonStrokeColorEraser = Ti.UI.createButton({ bottom:40, right:10, width:100, height:30, title:'Erase : Off' });
var buttonStrokeColorEraser = Ti.UI.createButton({
bottom: 40,
right: 10,
width: 100,
height: 30,
title: 'Erase : Off'
});
buttonStrokeColorEraser.addEventListener('click', function(e) {
paintView.eraseMode = (paintView.eraseMode) ? false : true;
e.source.title = (paintView.eraseMode) ? 'Erase : On' : 'Erase : Off';
paintView.eraseMode = (paintView.eraseMode) ? false : true;
e.source.title = (paintView.eraseMode) ? 'Erase : On' : 'Erase : Off';
});
win.add(buttonStrokeColorEraser);

win.open();
paintView.addEventListener('touchcancel', function(e) {
console.log('touchcancel event fired.');
});

paintView.addEventListener('touchend', function(e) {
console.log('touchend event fired.');
});

paintView.addEventListener('touchmove', function(e) {
console.log('touchmove event fired.');
});

paintView.addEventListener('touchstart', function(e) {
console.log('touchstart event fired.');
});

win.open();
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.4.0
version: 1.4.1
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Provides a paint surface user interface view.
Expand Down
2 changes: 1 addition & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 3.4.1.GA
TITANIUM_SDK_VERSION = 3.5.0.GA


//
Expand Down

0 comments on commit 5f3da9d

Please sign in to comment.