Code Monkey home page Code Monkey logo

Comments (7)

rob4226 avatar rob4226 commented on June 18, 2024

Hi @EddyVerbruggen thank you for this great plugin! I am unfortunately having the same issue since moving to NativeScript 8 on Android. As soon as the camera opens the app crashes:

System.err: An uncaught Exception occurred on "main" thread.
System.err: Calling js method onViewAttachedToWindow failed
System.err: TypeError: activity.getLifecycle is not a function
System.err:
System.err: StackTrace:
System.err: _onAttachedToWindow(file: src\webpack:\mobile\node_modules\@nativescript-community\ui-material-bottom-navigation\index.android.js:307:0)
System.err:     at AttachListener.onViewAttachedToWindow(file: src\webpack:\mobile\node_modules\@nativescript-community\ui-material-bottom-navigation\index.android.js:157:0)
System.err:     at com.tns.Runtime.callJSMethodNative(Native Method)
System.err:     at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err:     at com.tns.gen.java.lang.Object_vendor_576_28_AttachListener.onViewAttachedToWindow(Object_vendor_576_28_AttachListener.java:18)
System.err:     at android.view.View.dispatchAttachedToWindow(View.java:18418)
System.err:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3407)
System.err:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3414)
System.err:     at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3414)
System.err:     at android.view.ViewGroup.addViewInner(ViewGroup.java:5091)
System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4879)
System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4819)
System.err:     at android.view.ViewGroup.addView(ViewGroup.java:4792)
System.err:     at android.view.ViewOverlay$OverlayViewGroup.add(ViewOverlay.java:205)
System.err:     at android.view.ViewGroupOverlay.add(ViewGroupOverlay.java:72)
System.err:     at androidx.transition.ViewGroupOverlayApi18.add(ViewGroupOverlayApi18.java:48)
System.err:     at androidx.transition.Visibility.onDisappear(Visibility.java:428)
System.err:     at androidx.transition.Visibility.createAnimator(Visibility.java:257)
System.err:     at androidx.transition.Transition.createAnimators(Transition.java:747)
System.err:     at androidx.transition.TransitionSet.createAnimators(TransitionSet.java:480)
System.err:     at androidx.transition.Transition.playTransition(Transition.java:1821)
System.err:     at androidx.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:301)
System.err:     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:977)
System.err:     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2502)
System.err:     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1479)
System.err:     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7211)
System.err:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
System.err:     at android.view.Choreographer.doCallbacks(Choreographer.java:761)
System.err:     at android.view.Choreographer.doFrame(Choreographer.java:696)
System.err:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
System.err:     at android.os.Handler.handleCallback(Handler.java:873)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:99)
System.err:     at android.os.Looper.loop(Looper.java:193)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:6880)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:504)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

from nativescript-barcodescanner.

delanick avatar delanick commented on June 18, 2024

@rob4226 Have you found a solution to this yet?

Not sure if @EddyVerbruggen is still maintaining this repo or not.

from nativescript-barcodescanner.

rob4226 avatar rob4226 commented on June 18, 2024

@delanick I found that it is caused by some interaction between this barcode-scanner plugin and the @nativescript-community/ui-material-bottom-navigation plugin. Specifically, the error occurs when activity.getLifecycle() is called:

https://github.com/nativescript-community/ui-material-components/blob/2140ffc99ffe3ab1eef87ef8c8852e644c271b5b/src/bottom-navigation/index.android.ts#L400-L417

I am not sure what the exact problem is, or why it happens, but as a hack I added a check for the getLifecycle() function before calling it, which seems to have allowed everything to work. I changed lines 406 - 408 to:

if ((this._manager && this._manager.isDestroyed()) ||  (activity.hasOwnProperty('getLifecycle') && !activity.getLifecycle().getCurrentState().isAtLeast(androidx.lifecycle.Lifecycle.State.STARTED))) {
  return;
}

Note the addtional activity.hasOwnProperty('getLifecycle') && check. Although this makes it work, I don't know if it is the proper solution for it. Any idea's anyone??

from nativescript-barcodescanner.

delanick avatar delanick commented on June 18, 2024

@rob4226 that's awesome that you found a hack, well done and thank you for sharing! Which file do I make those changes on?

from nativescript-barcodescanner.

rob4226 avatar rob4226 commented on June 18, 2024

@delanick Np, I hope it works for you. We should probably follow up on this in the bottom-drawer plugin repo so maybe they can address it.

The file is located in the bottom-navigation plugin so in your project: node_modules/@nativescript-community/ui-material-bottom-navigation/index.android.js

You can try it first there to make sure it works for you but if it does, you are probably better off cloning that repo, then making the change in src/bottom-navigation/index.android.ts and building the plugin, then install it locally in your project so the change will be permanent. Otherwise, every time you run npm install for you project, your changes in your node_modules will be overwritten.

from nativescript-barcodescanner.

delanick avatar delanick commented on June 18, 2024

@rob4226 thanks so much, got it working. My file was different to yours as I have bottom nav installed separately. But it works, which is what matters.

As for your other point, yep, exactly that - will need to clone and build the plugin myself. Issue is, I'm a noob when it comes to plugins, so have no idea how to build it. Any advice?

from nativescript-barcodescanner.

timdoege avatar timdoege commented on June 18, 2024

You can
Clone the project

cd NativeScript/plugins
git clone [email protected]:EddyVerbruggen/nativescript-barcodescanner.git
cd nativescript-barcodescanner
-- Optional: apply PR 278 to prevent iOS full screen crashes - requires Github CLI --
gh pr checkout 278
cd src
-- change version to 4.1.3 in package.json --
npm run build                                                         
cd publish
./pack.sh
mv package/nativescript-barcodescanner-4.1.3.tgz ~/my-app-folder/plugins

Update package.jsonto use local file

"nativescript-barcodescanner": "file:plugins/nativescript-barcodescanner-4.1.3.tgz",

and run

ns clean
npm i

from nativescript-barcodescanner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.