mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
globals module added with setTimeout implementation for both iOS and Android
This commit is contained in:
@@ -169,6 +169,14 @@
|
|||||||
<TypeScriptCompile Include="promises\index.ts" />
|
<TypeScriptCompile Include="promises\index.ts" />
|
||||||
<TypeScriptCompile Include="http\http.ts" />
|
<TypeScriptCompile Include="http\http.ts" />
|
||||||
<TypeScriptCompile Include="ios7.d.ts" />
|
<TypeScriptCompile Include="ios7.d.ts" />
|
||||||
|
<TypeScriptCompile Include="globals\globals.android.ts">
|
||||||
|
<DependentUpon>globals.d.ts</DependentUpon>
|
||||||
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="globals\globals.d.ts" />
|
||||||
|
<TypeScriptCompile Include="globals\globals.ios.ts">
|
||||||
|
<DependentUpon>globals.d.ts</DependentUpon>
|
||||||
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="globals\index.ts" />
|
||||||
<Content Include="_references.ts" />
|
<Content Include="_references.ts" />
|
||||||
<TypeScriptCompile Include="Console\console.d.ts" />
|
<TypeScriptCompile Include="Console\console.d.ts" />
|
||||||
<Content Include="Image\Readme.md" />
|
<Content Include="Image\Readme.md" />
|
||||||
|
|||||||
@@ -22,11 +22,3 @@
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setTimeout(callback, milliseconds) {
|
|
||||||
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(
|
|
||||||
new java.lang.Runnable({
|
|
||||||
run: function () { callback(); }
|
|
||||||
}),
|
|
||||||
milliseconds);
|
|
||||||
}
|
|
||||||
5
globals/Readme.md
Normal file
5
globals/Readme.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
Globals module for defining functions part of the global context. For example setTimeout:
|
||||||
|
```js
|
||||||
|
require("globals");
|
||||||
|
setTimeout(function(){ log("Test"); }, 2000);
|
||||||
|
```
|
||||||
10
globals/globals.android.ts
Normal file
10
globals/globals.android.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Android specific global functions implementation.
|
||||||
|
*/
|
||||||
|
export function setTimeout(callback: Function, milliseconds: number): void {
|
||||||
|
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(
|
||||||
|
new java.lang.Runnable({
|
||||||
|
run: function () { callback(); }
|
||||||
|
}),
|
||||||
|
long(milliseconds));
|
||||||
|
}
|
||||||
4
globals/globals.d.ts
vendored
Normal file
4
globals/globals.d.ts
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* global functions.
|
||||||
|
*/
|
||||||
|
export declare function setTimeout(callback: Function, milliseconds: number): void;
|
||||||
7
globals/globals.ios.ts
Normal file
7
globals/globals.ios.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* iOS specific global functions implementation.
|
||||||
|
*/
|
||||||
|
export function setTimeout(callback: Function, milliseconds: number): void {
|
||||||
|
var target = Foundation.NSObject.extends({ tick: function (timer) { callback(); } }, { exposedMethods: { "tick:": "v@:@" } });
|
||||||
|
Foundation.NSTimer.scheduledTimerWithTimeIntervalTargetSelectorUserInfoRepeats(milliseconds / 1000, new target(), "tick:", null, false);
|
||||||
|
}
|
||||||
5
globals/index.ts
Normal file
5
globals/index.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
declare var module, setTimeout;
|
||||||
|
import globals = require("globals/globals");
|
||||||
|
module.exports = globals;
|
||||||
|
|
||||||
|
setTimeout = globals.setTimeout;
|
||||||
Reference in New Issue
Block a user