NativeScript / theme

@nativescript/theme
https://v7.docs.nativescript.org/ui/theme
Apache License 2.0
127 stars 44 forks source link

getTheme not working on app startup #258

Open erjdriver opened 4 years ago

erjdriver commented 4 years ago

Using the latest release 2.3.3 of theme and NS.

On Android platform, Theme.getMode() doesn't work on app startup.

I've got my phone Display settings in Dark theme.

When the app starts up (before run) - I do a getMode() and it returns ns-light.

Shouldn't it return ns-dark.

The app does start up in Dark theme.

This seems to be related to issue #232

I'm also intercepting systemAppearanceChangedEvent callback - when this event is called has the app already changed to the new theme or do I have to call Theme.setMode().

Thank you.

erjdriver commented 4 years ago

Weird bug!

This is using NS 6.5 w/ latest ns-theme plugin and Android platform.

Create a new project using

tns create testproject --tsc template

run on device and toggle the device theme - works fine.

Now go to app.ts and add the following line before application.run

Theme.getMode() along with the import.

The colors no longer change on device theme toggle.

bundyo commented 4 years ago

Can you check if this works with the latest @next version?

erjdriver commented 4 years ago

No.

Returns the wrong result and now crashes.

JavaScript error:
file: node_modules/@nativescript/theme/index.js:132:0: JS ERROR TypeError: undefined is not an object (evaluating 'Theme.currentMode.substr')
(CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: undefined is not an object (evaluating 'Theme.currentMode.substr')
at
file: node_modules/@nativescript/theme/index.js:132:0
at onLoaded(file: app/app-root.ts:15:67)
at file: node_modules/@nativescript/core/data/observable/observable.js:110:0
at file: node_modules/@nativescript/core/data/observable/observable.js:127:0
at file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:237:0
at file: node_modules/nativescript-ui-sidedrawer/ui-sidedrawer.ios.js:49:0
at file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:317:75
at file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:310:0
at file: node_modules/@nativescript/core/ui/core/view-base/view-base.js:317:0
at file: node_modules/@nativescript/core/ui/core/view/view-helper/view-helper.ios.js:228:0
at makeKeyAndVisible([native code])
at file: node_modules/@nativescript/core/application/application.ios.js:252:0
at file: node_modules/@nativescript/core/application/application.ios.js:174:0
at file: node_modules/@nativescript/core/application/application.ios.js:163:0
at [native code]
at file: node_modules/@nativescript/core/application/application.ios.js:36:0
at UIApplicationMain([native code])
at run(file: node_modules/@nativescript/core/application/application.ios.js:312:0)
at file:///app/bundle.js:1664:69
at ./app.ts(file:///app/bundle.js:1681:34)
at __webpack_require__(file: app/webpack/bootstrap:750:0)
at checkDeferredModules(file: app/webpack/bootstrap:43:0)
at webpackJsonpCallback(file: app/webpack/bootstrap:30:0)
at anony<…>
NativeScript caught signal 6.
Native Stack:
1   0x10d74bbe1 sig_handler(int)
2   0x7fff51b2f5fd _sigtramp
3   0x7fff51a23f39 itoa64
4   0x7fff51a1fb7c abort
5   0x7fff4f927858 abort_message
6   0x7fff4f918cbf demangling_unexpected_handler()
7   0x7fff50ad7c0b _objc_terminate()
8   0x7fff4f926c87 std::__terminate(void (*)())
9   0x7fff4f926c29 std::terminate()
10  0x7fff519128df _dispatch_client_callout
11  0x7fff51915292 _dispatch_block_invoke_direct
12  0x7fff36c816e9 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
13  0x7fff36c813d7 -[FBSSerialQueue _queue_performNextIfPossible]
14  0x7fff36c818e6 -[FBSSerialQueue _performNextFromRunLoopSource]
15  0x7fff23d9deb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
16  0x7fff23d9dddc __CFRunLoopDoSource0
17  0x7fff23d9d5b4 __CFRunLoopDoSources0
18  0x7fff23d981ae __CFRunLoopRun
19  0x7fff23d97ac4 CFRunLoopRunSpecific
20  0x7fff38b2fc1a GSEventRunModal
21  0x7fff48bc7f80 UIApplicationMain
22  0x10e137e0d ffi_call_unix64
23  0x112883f70
JS Stack:
UIApplicationMain([native code])
at run(file: node_modules/@nativescript/core/application/application.ios.js:312:0)
at file:///app/bundle.js:1664:69
at ./app.ts(file:///app/bundle.js:1681:34)
at __webpack_require__(file: app/webpack/bootstrap:750:0)
at checkDeferredModules(file: app/webpack/bootstrap:43:0)
at webpackJsonpCallback(file: app/webpack/bootstrap:30:0)
at anonymous(file:///app/bundle.js:2:61)
at evaluate([native code])
at moduleEvaluation
at
at asyncFunctionResume
at
at promiseReactionJob