Skip to content

Commit b3a14fe

Browse files
author
Nataliya Hristova
authored
fix: change method to be called earlier (#388)
1 parent 2385d14 commit b3a14fe

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

assets/runtime/ios/files/ios-runtime-1203/main-view-model.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
In NativeScript, a file with the same name as an XML file is known as
3+
a code-behind file. The code-behind is a great place to place your view
4+
logic, and to set up your page’s data binding.
5+
*/
6+
7+
/*
8+
NativeScript adheres to the CommonJS specification for dealing with
9+
JavaScript modules. The CommonJS require() function is how you import
10+
JavaScript modules defined in other files.
11+
*/
12+
const createViewModel = require("./main-view-model").createViewModel;
13+
14+
function onNavigatingTo(args) {
15+
const myClassInstance = new MyClass();
16+
myClassInstance.logInfo();
17+
/*
18+
This gets a reference this page’s <Page> UI component. You can
19+
view the API reference of the Page to see what’s available at
20+
https://docs.nativescript.org/api-reference/classes/_ui_page_.page.html
21+
*/
22+
const page = args.object;
23+
24+
/*
25+
A page’s bindingContext is an object that should be used to perform
26+
data binding between XML markup and JavaScript code. Properties
27+
on the bindingContext can be accessed using the {{ }} syntax in XML.
28+
In this example, the {{ message }} and {{ onTap }} bindings are resolved
29+
against the object returned by createViewModel().
30+
31+
You can learn more about data binding in NativeScript at
32+
https://docs.nativescript.org/core-concepts/data-binding.
33+
*/
34+
page.bindingContext = createViewModel();
35+
}
36+
37+
/*
38+
Exporting a function in a NativeScript code-behind file makes it accessible
39+
to the file’s corresponding XML file. In this case, exporting the onNavigatingTo
40+
function here makes the navigatingTo="onNavigatingTo" binding in this page’s XML
41+
file work.
42+
*/
43+
exports.onNavigatingTo = onNavigatingTo;

tests/runtimes/ios/ios_runtime_tests.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,19 +300,18 @@ def test_392_use_objective_c_plus_plus_file(self):
300300
os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'), True)
301301

302302
File.copy(os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files', 'ios-runtime-1203',
303-
'main-view-model.js'),
304-
os.path.join(APP_PATH, 'app', 'main-view-model.js'), True)
303+
'main-page.js'),
304+
os.path.join(APP_PATH, 'app', 'main-page.js'), True)
305305
log = Tns.run_ios(app_name=APP_NAME, emulator=True)
306306

307-
# Verify app is running on device
308-
Device.wait_for_text(self.sim, text='Tap the button')
309-
Device.click(self.sim, text="TAP", case_sensitive=True)
310-
311307
strings = ['NativeScript logInfo method called']
312308
result = Wait.until(lambda: all(string in File.read(log.log_file) for string in strings), timeout=300,
313309
period=5)
314310
assert result, 'It seems that there\'s a problem with using objective C++ files that are added in App_Resources'
315311

312+
# Verify app is running on device
313+
Device.wait_for_text(self.sim, text='Tap the button')
314+
316315
def test_398_tns_run_ios_console_time(self):
317316
# Delete src folder from the previous test till Folder copy strt to backup folders too
318317
Folder.clean(os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'))

0 commit comments

Comments
 (0)