react-device-detect icon indicating copy to clipboard operation
react-device-detect copied to clipboard

OsTypes.Android either not working, or documentation doesn't make sense

Open ericblade opened this issue 3 years ago • 4 comments

import { OsTypes } from 'react-device-detect';

...

if (OsTypes.Android) {
    console.warn('* Android detected');
}

warns that it's Android no matter what browser/platform i'm on.

enums documentation seems to indicate that that should work?

image

ericblade avatar Jan 18 '22 05:01 ericblade

Detect this way.

import { mobileVendor, mobileModel } from 'react-device-detect';

function App() {

    console.log( "Company ->", mobileVendor ) // Apple
    console.log( "Model ->", mobileModel ) // iPhone

    return (
        <>
            <div className={`App ${mobileVendor} ${mobileModel}`}> // CSS Class

gmkhussain avatar Jan 25 '22 11:01 gmkhussain

Detect this way.

Not really what I'm looking for. I think this is an issue in the documentation being totally incorrect.

What does work:

import { isAndroid, isChrome } from 'react-device-detect';

if (isAndroid && isChrome) {
    do thing that is specific to Chrome on Android
}

ericblade avatar Jan 25 '22 11:01 ericblade

@ericblade You're right, it's a documentation issue. It's just a type, not a selector, you can compare it, for example, with osName, like this:

import { osName, OsTypes } from 'react-device-detect'

if (osName === OsTypes.Android) {
  // do something
}

Using it like it described in documentation right now is wrong, I will fix it in a future release. Thank you.

duskload avatar Jan 25 '22 13:01 duskload

That is kind of what I thought, but I poked around through the code and decided there was a lot of magic involved that I didn't have time to understand, and I noticed "isAndroid" which is exactly what I was going for anyway (have a specific issue that only affects Chrome on Android... sigh)

ericblade avatar Jan 25 '22 18:01 ericblade