An enhanced fork of the original TiDraggable module by Pedro Enrique, allows for simple creation of "draggable" views.
cancel
gesture to the end
gesture (firing the respective event).ensureRight
and ensureBottom
, this allows for stable dragging of views where the dimensions are not known.enabled
boolean property for toggeling dragdraggable
.var Draggable = require('ti.draggable'),
mainWindow = Ti.UI.createWindow({
backgroundColor : 'white'
}),
draggableView = Draggable.createView({
width : 100,
height : 100,
backgroundColor : 'black'
});
mainWindow.add(draggableView);
mainWindow.open();
If you are building the Android module, make sure you update the .classpath and build.properties files to match your setup.
Create a draggable view. All of Titanium's properties are supported along the additional draggableConfig
property containing any options that should be set upon creation. See Options
When the draggable proxy is created a new property is set called
draggable
which stores all the configuration properties and allows for options to be updated after creation.
iOS Notes
You can pass almost all of iOS' supported Ti.UI creation methods to the draggable module such as Draggable.createView( ... )
or Draggable.createWindow( ... )
. While Ti.UI.View
and Ti.UI.Window
are fully supported on iOS other APIs haven't been fully tested.
Android Notes Android only supports the creation of Ti.UI.Views. At this time there are no plans to add support for other APIs.
Options can be set on view creation using draggableConfig
or after creation using DraggableView.draggable.setConfig( ... )
The setConfig
method can set options two different ways. You can pass an object
containing the parameters you with to set or you can pass a key-value pair.
Setting Options With An Object
DraggableView.draggable.setConfig('enabled', false);
Setting Options With An Object
DraggableView.draggable.setConfig({
enabled : false
});
Boolean
- enabledFlag to enable or disable dragging.
Number
- minLeftThe left-most boundary of the view being dragged. Can be set to null
to disable property.
Number
- maxLeftThe right-most boundary of the view being dragged. Can be set to null
to disable property.
Number
- minTopThe top-most boundary of the view being dragged. Can be set to null
to disable property.
Number
- maxTopThe bottom-most boundary of the view being dragged. Can be set to null
to disable property.
Boolean
- ensureRightEnsure that that the right
edge of the view being dragged keeps its integrity. Can be set to null
to disable property.
Boolean
- ensureBottomEnsure that that the bottom
edge of the view being dragged keeps its integrity. Can be set to null
to disable property.
Array
- mapsAn array of views that should be translated along with the view being dragged. See View Mapping.
In the case where you want multiple views to be translated at the same time you can pass the maps
property to the draggable config. This functionality is useful for creating parallax or 1:1 movements.
The maps
property accepts an array of objects containing any of the following. The view
property is required.
Ti.UI.View
- viewThe view to translate.
Number
- parallaxAmountA positive or negative number. Numbers less than |1|
such as 0.1
, 0.2
, or 0.3
will cause the translation to move faster then the translation. A parallaxAmount
of 1 will translate mapped views 1:1. A parallaxAmount > 1
will result in a slower translation.
Object
- constrainAn object containing the boundaries of the mapped view. Can have the following:
The work is largely based on Pedro Enrique's TiDraggable module license under the MIT (V2) license.