Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-25048
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Aug 11, 2018
2 parents 6189fbe + 5fa08ed commit 0ad5da9
Show file tree
Hide file tree
Showing 13 changed files with 640 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
@Kroll.proxy(creatableInModule = UIModule.class,
propertyAccessors = {
TiC.PROPERTY_CACHE_SIZE,
TiC.PROPERTY_CLIP_VIEWS,
TiC.PROPERTY_PADDING,
TiC.PROPERTY_SHOW_PAGING_CONTROL,
TiC.PROPERTY_OVER_SCROLL_MODE
})
Expand Down Expand Up @@ -58,6 +60,7 @@ public ScrollableViewProxy()
super();
inScroll = new AtomicBoolean(false);
defaultValues.put(TiC.PROPERTY_CACHE_SIZE, MIN_CACHE_SIZE);
defaultValues.put(TiC.PROPERTY_CLIP_VIEWS, true);
defaultValues.put(TiC.PROPERTY_SHOW_PAGING_CONTROL, false);
defaultValues.put(TiC.PROPERTY_OVER_SCROLL_MODE, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package ti.modules.titanium.ui.widget;

import java.util.ArrayList;
import java.util.HashMap;
import java.lang.Math;

import org.appcelerator.kroll.KrollDict;
Expand Down Expand Up @@ -75,6 +76,9 @@ public TiUIScrollableView(ScrollableViewProxy proxy)
mViews = new ArrayList<TiViewProxy>();
mAdapter = new ViewPagerAdapter(activity, mViews);
mPager = buildViewPager(activity, mAdapter);
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_CLIP_VIEWS)) {
mPager.setClipToPadding(TiConvert.toBoolean(proxy.getProperty(TiC.PROPERTY_CLIP_VIEWS), true));
}
mContainer.addView(mPager, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

// Add paging controls to container.
Expand Down Expand Up @@ -396,6 +400,10 @@ public void processProperties(KrollDict d)
setPageCacheSize(TiConvert.toInt(d.get(TiC.PROPERTY_CACHE_SIZE)));
}

if (d.containsKey(TiC.PROPERTY_PADDING)) {
setPadding((HashMap) d.get(TiC.PROPERTY_PADDING));
}

super.processProperties(d);
}

Expand All @@ -411,6 +419,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
} else {
hidePager();
}
} else if (TiC.PROPERTY_PADDING.equals(key)) {
setPadding((HashMap) newValue);
} else if (TiC.PROPERTY_SCROLLING_ENABLED.equals(key)) {
mEnabled = TiConvert.toBoolean(newValue);
} else if (TiC.PROPERTY_OVER_SCROLL_MODE.equals(key)) {
Expand Down Expand Up @@ -638,6 +648,32 @@ public ArrayList<TiViewProxy> getViews()
return mViews;
}

private void setPadding(HashMap<String, Object> d)
{
int paddingLeft = mPager.getPaddingLeft();
int paddingRight = mPager.getPaddingRight();
int paddingTop = mPager.getPaddingTop();
int paddingBottom = mPager.getPaddingBottom();

if (d.containsKey(TiC.PROPERTY_LEFT)) {
paddingLeft = TiConvert.toInt(d.get(TiC.PROPERTY_LEFT), 0);
}

if (d.containsKey(TiC.PROPERTY_RIGHT)) {
paddingRight = TiConvert.toInt(d.get(TiC.PROPERTY_RIGHT), 0);
}

if (d.containsKey(TiC.PROPERTY_TOP)) {
paddingTop = TiConvert.toInt(d.get(TiC.PROPERTY_TOP), 0);
}

if (d.containsKey(TiC.PROPERTY_BOTTOM)) {
paddingBottom = TiConvert.toInt(d.get(TiC.PROPERTY_BOTTOM), 0);
}

mPager.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
}

@Override
public void release()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1507,6 +1507,22 @@ protected void onRestart()
}
}

@Override
/**
* When a key, touch, or trackball event is dispatched to the activity, this method fires the
* javascript 'userinteraction' event.
*/
public void onUserInteraction()
{
Log.d(TAG, "Activity " + this + " onUserInteraction", Log.DEBUG_MODE);

if (activityProxy != null) {
activityProxy.fireEvent(TiC.EVENT_USER_INTERACTION, null);
}

super.onUserInteraction();
}

@Override
/**
* When the activity is about to go into the background as a result of user choice, this method fires the
Expand Down
10 changes: 10 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,11 @@ public class TiC
*/
public static final String EVENT_USER_LEAVE_HINT = "userleavehint";

/**
* @module.api
*/
public static final String EVENT_USER_INTERACTION = "userinteraction";

/**
* @module.api
*/
Expand Down Expand Up @@ -1293,6 +1298,11 @@ public class TiC
*/
public static final String PROPERTY_CLEAR_ON_EDIT = "clearOnEdit";

/**
* @module.api
*/
public static final String PROPERTY_CLIP_VIEWS = "clipViews";

/**
* @module.api
*/
Expand Down
21 changes: 20 additions & 1 deletion apidoc/Titanium/Android/Activity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,29 @@ events:
summary: Fired when the activity is about to go into the background as a result of user choice.
description: |
See also:
[onPause](https://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint())
[onUserLeaveHint](https://developer.android.com/reference/android/app/Activity.html#onUserLeaveHint())
in the Android Developer Reference.
since: "3.2.0"

- name: userinteraction
summary: Called whenever a key, touch, or trackball event is dispatched to the activity.
description: |
Implement this method if you wish to know that the user has interacted with the device in some
way while your activity is running. This event and `userleavehint` are intended to help activities
manage status bar notifications intelligently; specifically, for helping activities determine the
proper time to cancel a notfication.
All calls to your activity's "userleavehint" event will be accompanied by calls to "userinteraction".
This ensures that your activity will be told of relevant user activity such as pulling down the
notification pane and touching an item there.
Note that this callback will be invoked for the touch down action that begins a touch gesture,
but may not be invoked for the touch-moved and touch-up actions that follow.
See also:
[onUserInteraction](https://developer.android.com/reference/android/app/Activity.html#onUserInteraction())
in the Android Developer Reference.
since: "7.4.0"

properties:

Expand Down
9 changes: 8 additions & 1 deletion apidoc/Titanium/UI/ScrollableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ properties:
type: Boolean
availability: creation
default: true
platforms: [iphone, ipad]
since: { iphone: 0.9, ipad: 0.9, android: 7.4.0 }
platforms: [iphone, ipad, android]

- name: hitRect
summary: Sets the region where this view responds to gestures.
Expand All @@ -375,6 +376,12 @@ properties:
platforms: [iphone, ipad]
since: "2.1"

- name: padding
summary: The padding applied to the scrollable view.
platforms: [android]
type: ViewPadding
since: "7.4.0"

examples:
- title: Simple Scrollable View with 3 Views
example: |
Expand Down
25 changes: 2 additions & 23 deletions apidoc/Titanium/UI/TextArea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ properties:

- name: padding
summary: Sets the left and right padding of this TextArea. The text will always be vertically centered.
type: TextAreaPadding
type: ViewPadding
platforms: [android, iphone, ipad]
since: {android: "6.0.0", iphone: "6.1.0", ipad: "6.1.0"}

Expand Down Expand Up @@ -609,25 +609,4 @@ properties:

- name: length
summary: Number of characters selected.
type: Number
---
name: TextAreaPadding
summary: Dictionary object of parameters for the <Titanium.UI.TextArea.padding> that describes the padding
since: {android: "6.0.0", iphone: "6.1.0", ipad: "6.1.0"}
platforms: [android, iphone, ipad]
properties:
- name: left
type: Number
summary: Left padding

- name: right
type: Number
summary: Right padding

- name: top
type: Number
summary: Top padding

- name: bottom
type: Number
summary: Bottom padding
type: Number
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/TextField.yml
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ properties:

- name: padding
summary: Sets the padding of this text field.
type: TextFieldPadding
type: ViewPadding
platforms: [android, iphone, ipad]
since: 6.0.0

Expand Down
20 changes: 20 additions & 0 deletions apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1990,3 +1990,23 @@ properties:
type: Boolean
default: false
osver: {android: {min: 5.0}}

---
name: ViewPadding
summary: Dictionary object of parameters for the padding applied to all kinds of views.
properties:
- name: left
type: Number
summary: Left padding

- name: right
type: Number
summary: Right padding

- name: top
type: Number
summary: Top padding

- name: bottom
type: Number
summary: Bottom padding
40 changes: 24 additions & 16 deletions iphone/Classes/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,16 @@ - (void)didStartNewContext:(KrollContext *)kroll
// Make the global object itself available under the name "global"
TiStringRef globalPropertyName = TiStringCreateWithCFString((CFStringRef) @"global");
TiObjectSetProperty(jsContext, globalRef, globalPropertyName, globalRef, kTiPropertyAttributeDontEnum | kTiPropertyAttributeReadOnly | kTiPropertyAttributeDontDelete, NULL);
TiStringRelease(globalPropertyName);

// Set the __dirname and __filename for the app.js.
// For other files, it will be injected via the `TitaniumModuleRequireFormat` property
TiStringRef dirnameProperty = TiStringCreateWithCFString((CFStringRef) @"__dirname");
TiStringRef filenameProperty = TiStringCreateWithCFString((CFStringRef) @"__filename");
TiObjectSetProperty(jsContext, globalRef, dirnameProperty, [KrollObject toValue:kroll value:@"/"], kTiPropertyAttributeDontEnum | kTiPropertyAttributeReadOnly | kTiPropertyAttributeDontDelete, NULL);
TiObjectSetProperty(jsContext, globalRef, filenameProperty, [KrollObject toValue:kroll value:@"/app.js"], kTiPropertyAttributeDontEnum | kTiPropertyAttributeReadOnly | kTiPropertyAttributeDontDelete, NULL);
TiStringRelease(dirnameProperty);
TiStringRelease(filenameProperty);

//if we have a preload dictionary, register those static key/values into our namespace
if (preload != nil) {
Expand Down Expand Up @@ -887,22 +897,20 @@ - (NSString *)loadFile:(NSString *)path

- (KrollWrapper *)loadJavascriptObject:(NSString *)data fromFile:(NSString *)filename withContext:(KrollContext *)kroll
{
// We could cheat and just do "module.exports = %data%", but that wouldn't validate that the passed in content was JSON
// and may open a security hole.

// TODO It'd be good to try and handle things more gracefully if the JSON is "bad"/malformed

// Take JSON and turn into JS program that assigns module.exports to the parsed JSON
// 1. trim leading and trailing newlines and whitespace from JSON file
data = [data stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]];
// 2. Escape single quotes
data = [data stringByReplacingOccurrencesOfString:@"'" withString:@"\'"];
// 3. assign module.exports as JSON.parse call on the JSON
data = [@"module.exports = JSON.parse('" stringByAppendingString:data];
// 4. Replace newlines with "' +\n'"
data = [data stringByReplacingOccurrencesOfString:@"\n" withString:@"' +\n'"];
// 5. close the JSON string and end the JSON.parse call
data = [data stringByAppendingString:@"');"];
NSError *jsonParseError = nil;
NSError *jsonStringifyError = nil;

// 1. Parse JSON
__unused NSDictionary *parsedJSON = [TiUtils jsonParse:data error:&jsonParseError];

// 2. Validate parsed JSON
if (jsonParseError != nil) {
DebugLog(@"[ERROR] Unable to parse JSON input!");
return nil;
}

// 3. Assign valid JSON to module.exports
data = [NSString stringWithFormat:@"module.exports = %@;", data];

return [self loadJavascriptText:data fromFile:filename withContext:kroll];
}
Expand Down

0 comments on commit 0ad5da9

Please sign in to comment.