Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox prompt support for picker #86

Merged
merged 5 commits into from
May 31, 2018

Conversation

felipemartim
Copy link

@Noitidart here it is the original PR I owed you. Sorry, I'm just too busy right now and I couldn't even implement the changes you proposed, but maybe somebody can, so I'm opening this PR.

@Noitidart
Copy link
Collaborator

Nooo problemo thank you so much @felipemartim !! :)

@Noitidart
Copy link
Collaborator

May you please give me some examples on how to use this. I keep getting crashes.

@Noitidart
Copy link
Collaborator

Oops never mind got it! :)

@Noitidart
Copy link
Collaborator

Whew that took a few hours. Please see the changes. I modified the js api, and update the docs and js with types.

I also made it so that all things support this checkbox prompt. Only thing that does not support it is the progress dialog. The native module by afollstead doesn't support checkbox in progress dialog, I tried it.

Instead of passing a checkboxPrompt object I modified it so we just have to pass checkboxLabel. And optionally checkboxDefaultValue.

If things look ok to you @felipemartim I'm ready to merge. Thanks so much for this.

@Noitidart
Copy link
Collaborator

Noitidart commented May 31, 2018

Here is the examples section, redone with the options added for showing a checkbox along with images:

Alert with checkbox

const html = async () => {
    const res = await DialogAndroid.alert('Title', `This is a link <a href="https://www.duckduckgo.com/">DuckDuckGo</a>`, {
        contentIsHtml: true,
        checkboxLabel: 'This is a prompt checkbox',
        checkboxDefaultValue: true
    });
    console.log('html :: res:', res);
}

Basic list with checkbox

const listBasic = async () => {
    const res = await DialogAndroid.showPicker('Pick a fruit', null, {
        items: [
            { label:'Apple', id:'apple' },
            { label:'Orange', id:'orange' },
            { label:'Pear', id:'pear' }
        ],
        checkboxLabel: 'This is a prompt checkbox',
        checkboxDefaultValue: true
    });
    console.log('listBasic :: res:', res);
}

Radio list with checkbox

const listRadio = async () => {
    const res = await DialogAndroid.showPicker('Pick a fruit', null, {
        positiveText: 'OK',
        negativeText: 'Cancel',
        type: DialogAndroid.listRadio,
        selectedId: 'apple',
        items: [
            { label:'Apple', id:'apple' },
            { label:'Orange', id:'orange' },
            { label:'Pear', id:'pear' }
        ],
        checkboxLabel: 'This is a prompt checkbox',
        checkboxDefaultValue: true
    });
    console.log('listRadio :: res:', res);
}

Checklist with checkbox

const listChecklistClear = async () => {
    const res = await DialogAndroid.showPicker('Select multiple fruits', null, {
        type: DialogAndroid.listCheckbox,
        selectedIds: ['apple', 'orange'],
        neutralIsClear: true,
        neutralText: 'Clear',
        items: [
            { label:'Apple', id:'apple' },
            { label:'Orange', id:'orange' },
            { label:'Pear', id:'pear' }
        ],
        checkboxLabel: 'This is a prompt checkbox',
        checkboxDefaultValue: true
    });
    console.log('listChecklistClear :: res:', res);
}

Prompt with checkbox

const prompt = async () => {
    const res = await DialogAndroid.prompt('Title - optional', 'Message - optional', {
        checkboxLabel: 'This is a prompt checkbox',
        checkboxDefaultValue: true
    });
    console.log('prompt :: res:', res);
}

@Noitidart
Copy link
Collaborator

Hey I was going to do a release to npm so was going to merge this. But please take a look at my changes when you get a chance!

@Noitidart Noitidart merged commit f633163 into react-native-dialogs:master May 31, 2018
@Noitidart
Copy link
Collaborator

@felipemartim - in a fresh app that i install this, using the radio list (without auto dismiss) works fine. But when I try it in my actual app I am getting a crash due to:

05-31 15:39:19.743  3010  3010 E AndroidRuntime: FATAL EXCEPTION: main
05-31 15:39:19.743  3010  3010 E AndroidRuntime: Process: com.did, PID: 3010
05-31 15:39:19.743  3010  3010 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/animation/AnimatorCompatHelper;
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.DefaultItemAnimator.resetAnimation(DefaultItemAnimator.java:515)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.DefaultItemAnimator.animateChange(DefaultItemAnimator.java:322)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.SimpleItemAnimator.animateChange(SimpleItemAnimator.java:149)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.RecyclerView.animateChange(RecyclerView.java:3759)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.RecyclerView.dispatchLayoutStep3(RecyclerView.java:3566)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3265)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3767)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at com.afollestad.materialdialogs.internal.MDRootLayout.onLayout(MDRootLayout.java:259)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:2697)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.View.layout(View.java:16694)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:5481)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2228)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1981)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1140)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6239)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.Choreographer.doCallbacks(Choreographer.java:670)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.Choreographer.doFrame(Choreographer.java:606)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.os.Handler.handleCallback(Handler.java:739)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.os.Handler.dispatchMessage(Handler.java:95)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.os.Looper.loop(Looper.java:148)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at android.app.ActivityThread.main(ActivityThread.java:5551)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
05-31 15:39:19.743  3010  3010 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.animation.AnimatorCompatHelper" on path: DexPathList[[zip file "/data/app/com.did-2/base.apk"],nativeLibraryDirectories=[/data/app/com.did-2/lib/arm, /data/app/com.did-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        ... 50 more
05-31 15:39:19.743  3010  3010 E AndroidRuntime:        Suppressed: java.lang.ClassNotFoundException: android.support.v4.animation.AnimatorCompatHelper
05-31 15:39:19.743  3010  3010 E AndroidRuntime:                at java.lang.
05-31 15:39:21.339   369  1740 E NetlinkEvent: NetlinkEvent::decode(): buffer'Ç' size:128,format:1
05-31 15:39:21.339   369  1740 E NetlinkEvent: NetlinkEvent::decode(): buffer'Ç' size:128,format:1
05-31 15:39:21.339   369  1740 E NetlinkEvent: NetlinkEvent::decode(): buffer'l' size:108,format:1

Do you know how to fix this?

@Noitidart
Copy link
Collaborator

Oh sheesh. I had compile "com.android.support:appcompat-v7:27.0.2" in my build gradle. If I downgrade this to the default that comes with react native of 23.0.1 then it works. Do you know why this is? Is there anyway to keep using 27.0.2?

@felipemartim
Copy link
Author

Wow, amazing what you did here!

I was totally disconnected the last few days, so I haven't even seen your questions here, sorry for that. I should have at least updated the README with some instructions.

I don't know about the appcompat version, and I hope you have figured it all out, 'cause native Android development is not my specialty.

@Noitidart
Copy link
Collaborator

Thank you @felipemartim ! :) Thanks to your initial efforts I was able to copy that to the other parts and the js api. Team work is a synergy! Thank you for getting it started.

No problem about the appcompat I'll mention in the readme that this relies on that v4 stuff so it won't work if it's missing. :) Hopefully some android specialists will be able to clarify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants