Skip to content

Commit

Permalink
Add support for JVFloatLabeledTextView #1
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreGUI committed Jun 27, 2015
1 parent 917c535 commit 27bffab
Show file tree
Hide file tree
Showing 83 changed files with 971 additions and 77 deletions.
43 changes: 35 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,57 @@ Download this repository or one release and install it:
* Require the module in a view:

```xml
<Module module="ts.floatlabelfield" id="floatField" />
<!-- TextField -->
<Module module="ts.floatlabelfield" method="createTextFieldView" id="floatField" />
<!-- TextView -->
<Module module="ts.floatlabelfield" method="createTextViewView" id="floatView" />
```
Which create a reference in your controller, accessible via: `$.floadField`

* Or, require it directly in a controller :

```javascript
var floatlabelfield = require('ts.floatlabelfield').createView({ _[PARAMS]_ );
var floatlabelfield = require('ts.floatlabelfield').createTextFieldView({ _[PARAMS]_ );
var floatlabelview = require('ts.floatlabelfield').createTextFieldView({ _[PARAMS]_ );
```
**Example:**
```javascript
var win = Ti.UI.createWindow({ backgroundColor:'#fff' });
var floatlabelfield = require('ts.floatlabelfield').createView({
var flf = require('ts.floatlabelfield');

// open a single window
var win = Ti.UI.createWindow({
backgroundColor:'white',
layout: 'vertical'
});

var floatlabelfield = flf.createTextFieldView({
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
top: 150,
fontSize: '18dp',
textColor: '#2c3e50',
placeholderTextColor: '#bdc3c7',
placeholderTextColor: '#8d8d8d',
placeholderText: "short description",
floatingLabelFontSize: '20dp',
floatingLabelTextColor: "#2980b9"
floatingLabelFontSize: '12dp',
floatingLabelTextColor: "#2980b9",
debug: false
});
win.add(floatlabelfield);

var floatlabelview = flf.createTextViewView({
height: 150,
width: 150,
top: 50,
fontSize: '10dp',
textColor: '#2c3e50',
placeholderTextColor: '#bdc3c7',
placeholderText: "short description",
floatingLabelFontSize: '7dp',
floatingLabelTextColor: "#2980b9",
debug: false
});
win.add(floatlabelview);
win.open();
```
Expand Down Expand Up @@ -94,7 +121,7 @@ You can listen for events by simply adding an event listener:
* In an Alloy view:
```xml
<Module module="ts.floatlabelfield" id="floatField" onChange="onFieldChange" />
<Module module="ts.floatlabelfield" method="createTextFieldView" id="floatField" onChange="onFieldChange" />
```
* In an Alloy controller:
Expand Down
29 changes: 24 additions & 5 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
var flf = require('ts.floatlabelfield');

// open a single window
var win = Ti.UI.createWindow({
backgroundColor:'white'
backgroundColor:'white',
layout: 'vertical'
});
var floatlabelfield = require('ts.floatlabelfield').createView({

var floatlabelfield = flf.createTextFieldView({
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
top: 150,
fontSize: '18dp',
textColor: '#2c3e50',
placeholderTextColor: '#bdc3c7',
placeholderTextColor: '#8d8d8d',
placeholderText: "short description",
floatingLabelFontSize: '20dp',
floatingLabelTextColor: "#2980b9"
floatingLabelFontSize: '12dp',
floatingLabelTextColor: "#2980b9",
debug: false
});
win.add(floatlabelfield);

var floatlabelview = flf.createTextViewView({
height: 150,
width: 150,
top: 50,
fontSize: '10dp',
textColor: '#2c3e50',
placeholderTextColor: '#bdc3c7',
placeholderText: "short description",
floatingLabelFontSize: '7dp',
floatingLabelTextColor: "#2980b9",
debug: false
});
win.add(floatlabelview);
win.open();
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#import "TiUIView.h"
#import "JVFloatLabeledTextField.h"
#import "JVFloatLabeledTextView.h"

@interface TsFloatlabelfieldView : TiUIView<UITextFieldDelegate>
@interface TsFloatlabelfieldTextFieldView : TiUIView<UITextFieldDelegate>
{
JVFloatLabeledTextField *fltf;
NSString *placeholderText;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#import "TsFloatlabelfieldView.h"
#import "TsFloatlabelfieldViewProxy.h"
#import "TsFloatlabelfieldTextFieldView.h"
#import "TsFloatlabelfieldTextFieldViewProxy.h"

@implementation TsFloatlabelfieldView
@implementation TsFloatlabelfieldTextFieldView

-(JVFloatLabeledTextField*)FLTF
{
Expand Down
7 changes: 7 additions & 0 deletions ios/Classes/TsFloatlabelfieldTextFieldViewProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import "TiViewProxy.h"

@interface TsFloatlabelfieldTextFieldViewProxy: TiViewProxy
{
NSString *value;
}
@end
24 changes: 24 additions & 0 deletions ios/Classes/TsFloatlabelfieldTextFieldViewProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#import "TsFloatlabelfieldTextFieldViewProxy.h"
#import "TsFloatlabelfieldTextFieldView.h"
@implementation TsFloatlabelfieldTextFieldViewProxy

-(void)viewDidAttach
{
ENSURE_UI_THREAD_0_ARGS;
TsFloatlabelfieldTextFieldView * view = (TsFloatlabelfieldTextFieldView *)[self view];
}


-(void)setValue:(id)text
{
ENSURE_STRING(text);
[(TsFloatlabelfieldTextFieldView*)[self view] performSelectorOnMainThread:@selector(setValue:)
withObject:text waitUntilDone:NO];
}
-(NSString *)value
{
return [(TsFloatlabelfieldTextFieldView*)[self view] getValue];
}

@end
13 changes: 13 additions & 0 deletions ios/Classes/TsFloatlabelfieldTextViewView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "TiUIView.h"
#import "JVFloatLabeledTextView.h"

@interface TsFloatlabelfieldTextViewView : TiUIView<UITextViewDelegate>
{
JVFloatLabeledTextView *fltf;
NSNumber *debug;
}

-(void)setValue:(id)text;
-(id)getValue;

@end
109 changes: 109 additions & 0 deletions ios/Classes/TsFloatlabelfieldTextViewView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

#import "TsFloatlabelfieldTextViewView.h"
#import "TsFloatlabelfieldTextViewViewProxy.h"

@implementation TsFloatlabelfieldTextViewView

-(JVFloatLabeledTextView*)FLTF
{
if (fltf==nil)
{
fltf = [[JVFloatLabeledTextView alloc] initWithFrame:CGRectZero];
fltf.delegate = self;
[self addSubview:fltf];
[self bringSubviewToFront:fltf];
fltf.translatesAutoresizingMaskIntoConstraints = NO;
}
return fltf;
}

-(void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
if(debug) NSLog(@"[FLFV] frameSizeChanged frame %@ : %@ ", NSStringFromCGRect(frame), NSStringFromCGRect(fltf.frame));
// If using Ti.UI.SIZE, frameSizeChanged is called with size (0,0). TODO
[TiUtils setView:fltf positionRect: bounds];
[super frameSizeChanged:frame bounds:bounds];
}

- (void)textViewDidChange:(UITextView *)textView
{
[[self proxy] fireEvent:@"change" withObject:[NSDictionary dictionaryWithObject:[(UITextView *)fltf text] forKey:@"value"]];
}

- (void) dealloc
{
fltf.delegate = nil;
RELEASE_TO_NIL(fltf);
[super dealloc];
}


#pragma mark Public API

-(void)setValue:(id)text
{
if(debug) NSLog(@"[FLFV] setValue %@", text);
[self FLTF].text = text;
}
-(id)getValue
{
if(debug) NSLog(@"[FLFV] getValue");
return [self FLTF].text;
}

-(void)setValue_:(id)text
{
ENSURE_SINGLE_ARG(text, NSString);
[self setValue:text];
}

-(void)setFontSize_:(id)size
{
if(debug) NSLog(@"[FLFV] setFontSize_");
[self FLTF].font = [UIFont systemFontOfSize:[TiUtils floatValue:size def:20]];
}

-(void)setTextColor_:(id)color
{
ENSURE_SINGLE_ARG(color, NSString);
if(debug) NSLog(@"[FLFV] setTextColor %@", color);

[self FLTF].tintColor = [[TiUtils colorValue:color] _color];
[self FLTF].textColor = [[TiUtils colorValue:color] _color];
}

-(void)setPlaceholderText_:(id)text
{
ENSURE_SINGLE_ARG(text, NSString);
if(debug) NSLog(@"[FLFV] setPlaceholderText");
[self FLTF].placeholder = text;
}

-(void)setPlaceholderTextColor_:(id)color
{
ENSURE_SINGLE_ARG(color, NSString);
if(debug) NSLog(@"[FLFV] setPlaceholderTextColor %@", color);
[self FLTF].placeholderTextColor = [[TiUtils colorValue:color] _color];
}

-(void)setFloatingLabelFontSize_:(id)size
{
if(debug) NSLog(@"[FLFV] setFloatingLabelFontSize_");
[self FLTF].floatingLabelFont = [UIFont boldSystemFontOfSize:[TiUtils floatValue:size def:10]];
}

-(void)setFloatingLabelTextColor_:(id)color
{
if(debug) NSLog(@"[FLFV] setFloatingLabelTextColor_");
ENSURE_SINGLE_ARG(color, NSString);
// Use the TiUtils methods to get the values from the arguments
[self FLTF].floatingLabelTextColor = [[TiUtils colorValue:color] _color];
[self FLTF].floatingLabelActiveTextColor = [[TiUtils colorValue:color] _color];
}

-(void)setDebug_:(id)yesno
{
debug = [TiUtils boolValue:yesno];
}

@end
7 changes: 7 additions & 0 deletions ios/Classes/TsFloatlabelfieldTextViewViewProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import "TiViewProxy.h"

@interface TsFloatlabelfieldTextViewViewProxy: TiViewProxy
{
NSString *value;
}
@end
24 changes: 24 additions & 0 deletions ios/Classes/TsFloatlabelfieldTextViewViewProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#import "TsFloatlabelfieldTextViewViewProxy.h"
#import "TsFloatlabelfieldTextViewView.h"
@implementation TsFloatlabelfieldTextViewViewProxy

-(void)viewDidAttach
{
ENSURE_UI_THREAD_0_ARGS;
TsFloatlabelfieldTextViewView * view = (TsFloatlabelfieldTextViewView *)[self view];
}


-(void)setValue:(id)text
{
ENSURE_STRING(text);
[(TsFloatlabelfieldTextViewView*)[self view] performSelectorOnMainThread:@selector(setValue:)
withObject:text waitUntilDone:NO];
}
-(NSString *)value
{
return [(TsFloatlabelfieldTextViewView*)[self view] getValue];
}

@end
7 changes: 0 additions & 7 deletions ios/Classes/TsFloatlabelfieldViewProxy.h

This file was deleted.

24 changes: 0 additions & 24 deletions ios/Classes/TsFloatlabelfieldViewProxy.m

This file was deleted.

Binary file modified ios/build/Release-iphoneos/libTsFloatlabelfield.a
Binary file not shown.
Binary file modified ios/build/Release-iphonesimulator/libTsFloatlabelfield.a
Binary file not shown.
Binary file modified ios/build/libts.floatlabelfield.a
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/JVFloatLabeledTextView.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldModule.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/NSString+TextDirectionality.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldViewProxy.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldView.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldTextFieldViewProxy.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldTextViewViewProxy.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldTextFieldView.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/JVFloatLabeledTextField.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldTextViewView.o
/Users/pierre/TheSmiths/ts.floatlabelfield/ios/build/ts.floatlabelfield.build/Release-iphoneos/ts.floatlabelfield.build/Objects-normal/arm64/TsFloatlabelfieldModuleAssets.o
Loading

0 comments on commit 27bffab

Please sign in to comment.