Skip to content

Commit

Permalink
Merge branch 'master' into TIMOB-27429
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjsamir committed Aug 7, 2020
2 parents d0c6baf + 178bf92 commit e831f0b
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 84 deletions.
Expand Up @@ -5,17 +5,16 @@ description: |
Allows the creation of application shortcuts, which can be detected using
the `click` event from <Titanium.UI.Shortcut>.
Use the <Titanium.UI.createShortcut> method to manage shortcut creation.
In iOS, to use this feature make sure you have a 3D Touch compatible device. To
check for the feature, use the <Titanium.UI.iOS.forceTouchSupported> property.
On iOS, shortcuts are only supported on a 3D Touch compatible device.
Use the <Titanium.UI.iOS.forceTouchSupported> property to see if it's supported.
extends: Titanium.Proxy
since: "9.1.0"
platforms: [android, iphone, ipad]
osver: {android: {min: "7.1"}}
properties:
- name: items
summary: List current shortcuts.
summary: List dynamic shortcuts.
description: Array of shortcut items that were added to the app via the <Titanium.UI.Shortcut.add> method.
type: Array<Titanium.UI.ShortcutItem>
permission: read-only

Expand All @@ -26,32 +25,37 @@ properties:

methods:
- name: add
summary: Add shortcut to application.
summary: Adds a shortcut item to the application.
parameters:
- name: item
summary: <Titanium.UI.ShortcutItem> to add.
type: Titanium.UI.ShortcutItem

- name: remove
summary: Remove shortcut from application.
summary: Removes the given shortcut item from the application.
parameters:
- name: item
summary: <Titanium.UI.ShortcutItem> to remove.
type: Titanium.UI.ShortcutItem

- name: removeAll
summary: Remove all shortcuts from application.
summary: Removes all shortcut items from the application.

- name: getById
summary: Get shortcut by identifier.
summary: Fetches a shortcut item by its unique string identifier.
description: |
Returns a shortcut item with a matching string [id](Titanium.UI.ShortcutItem.id).
Returns `null` if a match was not found.
parameters:
- name: id
summary: Identifier of shortcut to obtain.
summary: Identifier of shortcut item to obtain.
type: String
returns:
type: Titanium.UI.ShortcutItem

events:
- name: click
summary: Fired when a <Titanium.UI.ShortcutItem> is clicked.
summary: Fired when a <Titanium.UI.ShortcutItem> was clicked on.
properties:
- name: item
summary: The shortcut item clicked.
Expand All @@ -66,27 +70,27 @@ examples:
``` javascript
const win = Ti.UI.createWindow({ backgroundColor: 'grey' });
const shortcut = Ti.UI.createShortcut();
shortcut.addEventListener('click', e => {
// Listen for shortcut item clicks from the end-user.
Ti.UI.Shortcut.addEventListener('click', e => {
// Event's "item" property indicates which shortcut item was clicked on.
console.log(`id: ${e.item.id}`);
// Set background to 'blue' on shortcut click event.
// Set background to 'blue' when a shortcut was clicked on.
win.backgroundColor = 'blue';
});
// Button to add a shortcut item
// Button to add a shortcut item.
const btn = Ti.UI.createButton({ title: 'ADD SHORTCUT' });
btn.addEventListener('click', () => {
// Add shortcut item to shortcut
const shortcutItem = Ti.UI.createShortcutItem({
id: 'test_shortcut',
title: 'TEST',
description: 'DESCRIPTION'
});
shortcut.add(shortcutItem);
Ti.UI.Shortcut.add(shortcutItem);
});
win.add(btn);
win.open();
```
53 changes: 50 additions & 3 deletions apidoc/Titanium/UI/ShortcutItem.yml
Expand Up @@ -5,10 +5,57 @@ description: |
Allows the creation of dynamic application shortcut items which can be set in the app to
offer a dynamic behavior at runtime.
Use the <Titanium.UI.createShortcutItem> method to create a shortcut
and <Titanium.UI.createShortcut> to manage shortcuts.
Use the <Titanium.UI.createShortcutItem> method to create a shortcut item and pass it to
the <Titanium.UI.Shortcut.add> method to add it to the application.
#### iOS static shortcuts
#### Android Static Shortcuts
Google documents how to add static shortcuts
[here](https://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts#static).
In the `tiapp.xml` file, you will need to add a shortcuts `<meta-data/>` element to your main activity.
``` xml
<ti:app>
<android>
<manifest>
<application>
<activity android:name=".<Yourapplicationname>Activity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
</activity>
</application>
</manifest>
</android>
</ti:app>
```
You will also need to create a `shortcuts.xml` file as shown below, defining all of the app's static shortcuts.
This file must reside in the Titanium project's `./platform/android/res/xml` folder. Note that XML attributes
`icon`, `shortcutShortLabel`, `shortcutLongLabel`, and `shortcutDisabledMessage` must be defined as string
resources under the project's `i18n` folders or `./platform/android/res/values` folders.
Attributes `targetPackage` and `targetClass` need to be set to your project id and app name.
``` xml
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="my_unique_string_id"
android:enabled="true"
android:icon="@drawable/my_shortcut_icon"
android:shortcutShortLabel="@string/my_shortcut_short_label"
android:shortcutLongLabel="@string/my_shortcut_long_label"
android:shortcutDisabledMessage="@string/my_shortcut_disabled_message">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="<id_from_tiapp_xml>"
android:targetClass="<id_from_tiapp_xml>.<Yourapplicationname>Activity" />
<categories android:name="android.shortcut.conversation" />
</shortcut>
<!-- Add more shortcuts here. -->
</shortcuts>
```
#### iOS Static Shortcuts
Static shortcut items can be set in the `<ios>` section of the `tiapp.xml` before launching the app.
Here is an example how to create static application shortcuts in the `tiapp.xml`:
Expand Down
34 changes: 34 additions & 0 deletions build/lib/test/test.js
Expand Up @@ -116,6 +116,8 @@ async function copyMochaAssets() {
})(),
// modules
fs.copy(path.join(SOURCE_DIR, 'modules'), path.join(PROJECT_DIR, 'modules')),
// platform
fs.copy(path.join(SOURCE_DIR, 'platform'), path.join(PROJECT_DIR, 'platform')),
// plugins
fs.copy(path.join(SOURCE_DIR, 'plugins'), path.join(PROJECT_DIR, 'plugins')),
// i18n
Expand Down Expand Up @@ -169,10 +171,36 @@ async function addTiAppProperties() {
content.push('\t\t\t\t\t\t<category android:name="android.intent.category.DEFAULT"/>');
content.push('\t\t\t\t\t\t<category android:name="android.intent.category.BROWSABLE"/>');
content.push('\t\t\t\t\t</intent-filter>');
content.push('\t\t\t\t\t<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>');
content.push('\t\t\t\t</activity>');
content.push('\t\t\t</application>');
content.push('\t\t\t<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>');
};
let insertPlistSettings = () => {
// Enable i18n support for the following languages.
content.push('\t\t\t\t<key>CFBundleLocalizations</key>');
content.push('\t\t\t\t<array>');
content.push('\t\t\t\t\t<string>en</string>');
content.push('\t\t\t\t\t<string>ja</string>');
content.push('\t\t\t\t</array>');
content.push('\t\t\t\t<key>CFBundleAllowMixedLocalizations</key>');
content.push('\t\t\t\t<true/>');

// Add a static shortcut.
content.push('\t\t\t\t<key>UIApplicationShortcutItems</key>');
content.push('\t\t\t\t<array>');
content.push('\t\t\t\t\t<dict>');
content.push('\t\t\t\t\t\t<key>UIApplicationShortcutItemIconType</key>');
content.push('\t\t\t\t\t\t<string>UIApplicationShortcutIconTypeSearch</string>');
content.push('\t\t\t\t\t\t<key>UIApplicationShortcutItemTitle</key>');
content.push('\t\t\t\t\t\t<string>static_shortcut1_title</string>');
content.push('\t\t\t\t\t\t<key>UIApplicationShortcutItemSubtitle</key>');
content.push('\t\t\t\t\t\t<string>static_shortcut1_subtitle</string>');
content.push('\t\t\t\t\t\t<key>UIApplicationShortcutItemType</key>');
content.push('\t\t\t\t\t\t<string>static_shortcut1</string>');
content.push('\t\t\t\t\t</dict>');
content.push('\t\t\t\t</array');
};

// Not so smart but this should work...
tiapp_xml_string.split(/\r?\n/).forEach(line => {
Expand All @@ -187,6 +215,12 @@ async function addTiAppProperties() {
content.push('\t\t<use-jscore-framework>true</use-jscore-framework>');
// force minimum ios sdk version of 12.0
content.push('\t\t<min-ios-ver>12.0</min-ios-ver>');
} else if (line.indexOf('<dict>') >= 0) {
// Insert iOS plist settings after the first <dict> element.
if (insertPlistSettings) {
insertPlistSettings();
insertPlistSettings = null;
}
// app thinning breaks tests which expect image files to exist on filesystem normally!
} else if (line.indexOf('<use-app-thinning>') >= 0) {
content.pop();
Expand Down
11 changes: 11 additions & 0 deletions iphone/Classes/UIModule.h
Expand Up @@ -17,6 +17,10 @@
#import "TiUIActivityIndicatorStyleProxy.h"
#endif

#if defined(USE_TI_UISHORTCUT) || defined(USE_TI_UISHORTCUTITEM)
#import "TiUIShortcutProxy.h"
#endif

@interface UIModule : TiModule {

@private
Expand All @@ -28,6 +32,9 @@
#endif
#ifdef USE_TI_UICLIPBOARD
TiProxy *clipboard;
#endif
#if defined(USE_TI_UISHORTCUT) || defined(USE_TI_UISHORTCUTITEM)
TiUIShortcutProxy *shortcut;
#endif
NSNumber *lastEmittedMode;
}
Expand Down Expand Up @@ -277,6 +284,10 @@
@property (nonatomic, readonly) TiUIActivityIndicatorStyleProxy *ActivityIndicatorStyle;
#endif

#if defined(USE_TI_UISHORTCUT) || defined(USE_TI_UISHORTCUTITEM)
@property (nonatomic, readonly) TiUIShortcutProxy *Shortcut;
#endif

@end

#endif
13 changes: 13 additions & 0 deletions iphone/Classes/UIModule.m
Expand Up @@ -60,6 +60,9 @@ - (void)dealloc
#ifdef USE_TI_UICLIPBOARD
[self forgetProxy:clipboard];
RELEASE_TO_NIL(clipboard);
#endif
#if defined(USE_TI_UISHORTCUT) || defined(USE_TI_UISHORTCUTITEM)
RELEASE_TO_NIL(shortcut);
#endif
[super dealloc];
}
Expand Down Expand Up @@ -739,6 +742,16 @@ - (NSString *)CLIPBOARD_OPTION_EXPIRATION_DATE
MAKE_SYSTEM_PROP(TABLE_VIEW_SEPARATOR_STYLE_NONE, UITableViewCellSeparatorStyleNone);
MAKE_SYSTEM_PROP(TABLE_VIEW_SEPARATOR_STYLE_SINGLE_LINE, UITableViewCellSeparatorStyleSingleLine);

#if defined(USE_TI_UISHORTCUT) || defined(USE_TI_UISHORTCUTITEM)
- (TiUIShortcutProxy *)Shortcut
{
if (shortcut == nil) {
shortcut = [[TiUIShortcutProxy alloc] init];
}
return shortcut;
}
#endif

@end

#endif
Expand Up @@ -16,12 +16,19 @@ UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"

FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"

XCODE_VERSION=$(/usr/libexec/PlistBuddy -c "Print :DTXcode" "$(xcode-select -p)/../Info.plist")

######################
# Build Frameworks
######################

xcodebuild -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
# Exclude arm64 architecture from simulator build in XCode 12+- TIMOB-28042

if [[ $XCODE_VERSION -ge 1200 ]]; then
xcodebuild -scheme ${PROJECT_NAME} -sdk iphonesimulator EXCLUDED_ARCHS=arm64 -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
else
xcodebuild -scheme ${PROJECT_NAME} -sdk iphonesimulator -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphonesimulator 2>&1
fi

xcodebuild -scheme ${PROJECT_NAME} -sdk iphoneos -configuration ${CONFIGURATION} clean build CONFIGURATION_BUILD_DIR=${BUILD_DIR}/${CONFIGURATION}-iphoneos 2>&1

Expand All @@ -42,7 +49,6 @@ mkdir "${FRAMEWORK}"

cp -r "${DEVICE_LIBRARY_PATH}/." "${FRAMEWORK}"


######################
# Make an universal binary
######################
Expand Down
5 changes: 5 additions & 0 deletions iphone/cli/commands/_buildModule.js
Expand Up @@ -473,6 +473,11 @@ iOSModuleBuilder.prototype.buildModule = function buildModule(next) {
args.push('CONFIGURATION_BUILD_DIR=' + path.join(this.projectDir, 'build', 'Release-' + target));
}

// Exclude arm64 architecture from simulator build in XCode 12+ - TIMOB-28042
if (target === 'iphonesimulator' && parseFloat(this.xcodeEnv.version) >= 12.0) {
args.push('EXCLUDED_ARCHS=arm64');
}

return args;
}.bind(this);

Expand Down
9 changes: 9 additions & 0 deletions support/iphone/build_titaniumkit.sh
Expand Up @@ -44,6 +44,8 @@ sed -i '' 's@__GITHASH__@'"$GIT_HASH"'@g' TitaniumKit/Sources/API/TopTiModule.m

REVEAL_ARCHIVE_IN_FINDER=false

XCODE_VERSION=$(/usr/libexec/PlistBuddy -c "Print :DTXcode" "$(xcode-select -p)/../Info.plist")

FRAMEWORK_NAME="TitaniumKit"

SIMULATOR_LIBRARY_PATH="$(pwd)/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework"
Expand All @@ -61,8 +63,15 @@ FRAMEWORK="${UNIVERSAL_LIBRARY_DIR}/${FRAMEWORK_NAME}.framework"
XCPRETTY="xcpretty"
which xcpretty || XCPRETTY="cat"

# Exclude arm64 architecture from simulator build in XCode 12+ - TIMOB-28042

if [[ $XCODE_VERSION -ge 1200 ]]; then
xcodebuild -scheme TitaniumKit -sdk iphonesimulator EXCLUDED_ARCHS=arm64 -configuration Release clean build CONFIGURATION_BUILD_DIR=build/Release-iphonesimulator | eval $XCPRETTY
[[ PIPESTATUS[0] -ne 0 ]] && exit 1
else
xcodebuild -scheme TitaniumKit -sdk iphonesimulator -configuration Release clean build CONFIGURATION_BUILD_DIR=build/Release-iphonesimulator | eval $XCPRETTY
[[ PIPESTATUS[0] -ne 0 ]] && exit 1
fi

xcodebuild -scheme TitaniumKit -sdk iphoneos -configuration Release clean build CONFIGURATION_BUILD_DIR=build/Release-iphoneos | eval $XCPRETTY
[[ PIPESTATUS[0] -ne 0 ]] && exit 1
Expand Down

0 comments on commit e831f0b

Please sign in to comment.