Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24101] Windows: Ability to use 3rd-party native classes

GitHub Issuen/a
TypeImprovement
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2017-04-11T13:09:08.000+0000
Affected Version/sRelease 5.4.0
Fix Version/sRelease 6.1.0, Hyperloop 2.1.0
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2016-11-04T06:38:01.000+0000
Updated2017-04-21T17:26:01.000+0000

Description

Add ability to use third-party dependencies in your Hyperloop enabled project. This may be done by putting WinMD(.winmd) or DLL (.dll) on certain place on your project. *Steps to test* 1. Create Windows Runtime Component Create Windows Runtime Component named WindowsRuntimeComponent1 from Visual Studio. Compile it and you should get WindowsRuntimeComponent1.winmd somewhere under in your Visual Studio project folder. You might want to use [^WindowsRuntimeComponent1.winmd] if you want to skip this step.
using System;

namespace WindowsRuntimeComponent1
{
    public sealed class Test
    {
        public int SampleNumber { get; set; }

        public static string SayHello(string str)
        {
            return String.Format("Hello, {0}!", str);
        }

        public string sayNumber()
        {
            return String.Format("SampleNumber is {0}.", SampleNumber);
        }
    }
}
2. Copy your WindowsRuntimeComponent1.winmd file into lib/windows/win10/x86/ folder under your Titanium app project folder.
var win = Ti.UI.createWindow({ backgroundColor: 'green' }),
    Test = require('WindowsRuntimeComponent1.Test'),
    test = new Test();

win.addEventListener('open', function() {
    alert(test.SayHello('World!'));
});

win.open();
3. Place appc.windows.js directly under your Titanium project folder. Make sure it contains names of your Windows Runtime component under hyperloop.windows.thirdparty key. It should look like below.
/**
 * Hyperloop configuration
 */
module.exports = {
	type: 'app',
	group: 'titanium',
	dependencies: {},
	hyperloop: {
		windows:
		{
			/**
			 * Optionally, you can bring in third-party or first-party Windows Runtime components.
			 * The 'key' is the root namespace of the component that will be used in the require.
			 * There's no values for now but we reserve them for future release.
			 *
			 * Place the library files into the lib/windows/(phone|store|win10)/(x86|ARM)/ folder under your app project.
			 * Hyperloop will pick up the winmd files and will generate necessary bindings and include the winmd in your app. 
			 */
			thirdparty: {
				'WindowsRuntimeComponent1': {}
			}
		}
	}
};
4. Make sure to enable hyperloop, and then run it using appc run -p windows --wp-sdk 10.0 --target ws-local -l trace. 5. Then you should see "Hello, World!!" dialog box in your Titanium app.

Attachments

FileDateSize
WindowsRuntimeComponent1.winmd2017-04-07T04:59:59.000+00006656

Comments

  1. Kota Iguchi 2017-04-07

    https://github.com/appcelerator/titanium_mobile_windows/pull/967
  2. Abir Mukherjee 2017-04-21

    Validated fix with this environment: Node Version: 6.10.1 NPM Version: 4.4.4 Appc CLI: 6.2.0 Appc CLI NPM: 4.2.9 Titanium SDK version: 6.1.0.v20170421082637 Appcelerator Studio, build: 4.8.1.201612050850 OS: Windows 10.0.14393 Targets: Windows 8.1 & 10 Devices. Windows 10 Emulator Hyperloop 2.1.0 FR passed with above environment, and fixes were verified in the SDK version noted above.

JSON Source