Skip to content

Commit

Permalink
Move layout processing to creationDict
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalduggal committed Apr 29, 2013
1 parent 7c83c2f commit c52cf9e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
34 changes: 31 additions & 3 deletions android/modules/ui/src/java/ti/modules/titanium/ui/ViewProxy.java
Expand Up @@ -6,17 +6,24 @@
*/
package ti.modules.titanium.ui;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.annotations.Kroll;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiUIView;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;

import ti.modules.titanium.ui.widget.TiView;
import android.app.Activity;

@Kroll.proxy(creatableInModule=UIModule.class)
public class ViewProxy extends TiViewProxy
{
protected TiCompositeLayout.LayoutParams layout;
protected LayoutArrangement arrangement = LayoutArrangement.DEFAULT;
public ViewProxy()
{
super();
Expand All @@ -26,13 +33,34 @@ public ViewProxy(TiContext tiContext)
{
this();
}

@Override
public void handleCreationDict(KrollDict options)
{
buildLayout(options);
super.handleCreationDict(options);
}

protected void buildLayout(KrollDict options) {
layout = new TiCompositeLayout.LayoutParams();
layout.autoFillsWidth = true;
layout.autoFillsHeight = true;
if (options.containsKey(TiC.PROPERTY_LAYOUT)) {
String layout = TiConvert.toString(options, TiC.PROPERTY_LAYOUT);
if (layout.equals(TiC.LAYOUT_HORIZONTAL)) {
arrangement = LayoutArrangement.HORIZONTAL;
} else if (layout.equals(TiC.LAYOUT_VERTICAL)) {
arrangement = LayoutArrangement.VERTICAL;
} }
TiConvert.fillLayout(options, layout);
}

@Override
public TiUIView createView(Activity activity)
{
TiUIView view = new TiView(this);
view.getLayoutParams().autoFillsHeight = true;
view.getLayoutParams().autoFillsWidth = true;
TiUIView view = new TiView(this, arrangement, layout);
//view.getLayoutParams().autoFillsHeight = true;
//view.getLayoutParams().autoFillsWidth = true;
return view;
}
}
Expand Up @@ -11,13 +11,21 @@
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutParams;
import org.appcelerator.titanium.view.TiUIView;

import android.view.View;

public class TiView extends TiUIView
{

public TiView(TiViewProxy proxy, LayoutArrangement arrangement, LayoutParams params) {
super(proxy);
this.layoutParams = params;
processLayout = false;
setNativeView(new TiCompositeLayout(proxy.getActivity(), arrangement, proxy));
}

public TiView(TiViewProxy proxy) {
super(proxy);
LayoutArrangement arrangement = LayoutArrangement.DEFAULT;
Expand Down
Expand Up @@ -122,7 +122,7 @@ public abstract class TiUIView

//to maintain sync visibility between borderview and view. Default is visible
private int visibility = View.VISIBLE;

protected boolean processLayout = true;

/**
* Constructs a TiUIView object with the associated proxy.
Expand Down Expand Up @@ -660,16 +660,18 @@ public void processProperties(KrollDict d)
nativeViewNull = true;
Log.d(TAG, "Nativeview is null", Log.DEBUG_MODE);
}
if (d.containsKey(TiC.PROPERTY_LAYOUT)) {
String layout = TiConvert.toString(d, TiC.PROPERTY_LAYOUT);
if (nativeView instanceof TiCompositeLayout) {
((TiCompositeLayout)nativeView).setLayoutArrangement(layout);
if (processLayout) {
if (d.containsKey(TiC.PROPERTY_LAYOUT)) {
String layout = TiConvert.toString(d, TiC.PROPERTY_LAYOUT);
if (nativeView instanceof TiCompositeLayout) {
((TiCompositeLayout)nativeView).setLayoutArrangement(layout);
}
}
if (TiConvert.fillLayout(d, layoutParams) && !nativeViewNull) {
nativeView.requestLayout();
}
}
if (TiConvert.fillLayout(d, layoutParams) && !nativeViewNull) {
nativeView.requestLayout();
}


if (d.containsKey(TiC.PROPERTY_HORIZONTAL_WRAP)) {
if (nativeView instanceof TiCompositeLayout) {
((TiCompositeLayout) nativeView).setEnableHorizontalWrap(TiConvert.toBoolean(d,TiC.PROPERTY_HORIZONTAL_WRAP,true));
Expand Down

0 comments on commit c52cf9e

Please sign in to comment.