Code Monkey home page Code Monkey logo

iamyellow.tigrowingtextfield's Introduction

TiGrowingTextField Appceleartor Titanium iOS Module

Description

This simple module let's you create a text field which grows or shinks depending on the the content the user types, like iMessage, WhatsApp, etc.

TiGrowingTextField uses a third party library created by HansPinckaers: https://github.com/HansPinckaers/GrowingTextView/

And it's open sourced: https://github.com/iamyellow/TiGrowingTextField

Using the module

Require the module and call and create the view:

var textField = require('net.iamyellow.tigrowingtextfield').createView({
	// layout stuff -it works as any other view-
	height: 40, // 40 is the minimum height, the view height won't be < 40
	left: 10, right: 10,
	// layout correction (new since v0.5)
	topCorrectionPadding: 7,
	sidesPadding: 5,
	// growing / shrink
	minNumberOfLines: 1, // default = 1
	maxNumberOfLines: 10, // default = 3,
	showKeyboardImmediately: true,
	// background stuff
	backgroundImage: 'images/MessageEntryInputField.png',
	backgroundLeftCap: 12,
	backgroundTopCap: 20,
	value: 'hellow',
	// appearance 
	appearance: Ti.UI.KEYBOARD_APPEARANCE_ALERT,
	// text stuff, works as Ti.UI.TextField
	autocorrect: false, // disables / enables autocorrection
	textAlign: 'left',
	font: {
		fontFamily: 'Georgia',
		fontSize: 12
	},
	color: '#333333'
});

I guess properties names are self explanatory, except showKeyboardImmediately... well, sometimes I need the keyboard appears immediately as window is opened. Setting this to true makes it possible.

Methods

focus ()

The field gains the focus.

blur ()

The field loses the focus.

Events

focus

When it gains the focus.

blur

When it loses the focus.

change

When the content changes. The event has properties:

  • value the content itself, the text field value.

  • height the current height.

Example

(function (tigrowingtextfield) {	
	// ****************************************************************************************************************
	// ****************************************************************************************************************
	// GUI setup
	
	var win = Ti.UI.createWindow({
		width: Ti.UI.FILL, height: Ti.UI.FILL,
		backgroundColor: '#fff612'
	}),
	toolbar = Ti.UI.createView({
		width: Ti.UI.FILL, height: Ti.UI.SIZE,
		top: 30, left: 0,
		backgroundImage: 'images/MessageEntryBackground.png',
		backgroundTopCap: 20
	}),
	// layout correction values 
	minHeight = 40,
	topCorrectionPadding = 7,
	sidesPadding = 5,
	// create view
	textField = tigrowingtextfield.createView({
		// layout, as any other view
		height: minHeight, // 0.5: once the view is inited, this is going to be the MIN height
		top: 0, left: 10, right: 10,
		// fine-tuning text adjustment (new on 0.5)
		topCorrectionPadding: topCorrectionPadding,
		sidesPadding: sidesPadding,
		// growing / shrink
		minNumberOfLines: 1, // default = 1
		maxNumberOfLines: 5, // default = 3,
		showKeyboardImmediately: true,
		// background
		backgroundImage: 'images/MessageEntryInputField.png',
		backgroundLeftCap: 15,
		backgroundTopCap: 20,
		// appearance 
		appearance: Ti.UI.KEYBOARD_APPEARANCE_ALERT,
		// text
		autocorrect: false,
		textAlign: 'left',
		font: {
			fontFamily: 'Helvetica',
			fontSize: 12
		},
		color: '#333'
	});
	
	toolbar.add(textField);
	win.add(toolbar);
	
	// ****************************************************************************************************************
	// ****************************************************************************************************************
	// events
	
	win.addEventListener('click', function () {
		textField.blur();
	});
	
	textField.addEventListener('focus', function (ev) {
		Ti.API.info('////////////////////////////////////////////////////////////');
		Ti.API.info('** focused');
	});
	
	textField.addEventListener('change', function (ev) {
		Ti.API.info('////////////////////////////////////////////////////////////');
		Ti.API.info('my value is: ' + ev.value);
		Ti.API.info('my height is: ' + ev.height);
	});
	
	textField.addEventListener('blur', function (ev) {
		Ti.API.info('////////////////////////////////////////////////////////////');
		Ti.API.info('** blurred');
	});
	
	
	// ****************************************************************************************************************
	// ****************************************************************************************************************
	// the show
	
	win.open();
})(require('net.iamyellow.tigrowingtextfield'));

Thanks to

Danny Pham for the funds for keep up to date this module.

Author

jordi domenech
[email protected]
http://iamyellow.net
@0xfff612

License

Copyright 2013 jordi domenech [email protected]
Apache License, Version 2.0

iamyellow.tigrowingtextfield's People

Contributors

iamyellow avatar neilgupta avatar

Watchers

James Cloos avatar Brenton House avatar

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.