mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-23 15:32:59 +02:00
Add API version and Input Events Level 2 for Android (#2618)
* Add API version and Input Events Level 2 for Android * Add input events level 2 for android without matching api version
This commit is contained in:
committed by
Ian Storm Taylor
parent
3dce916074
commit
bc256e027a
@@ -91,6 +91,43 @@ if (isBrowser) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array of regular expression matchers and their API version
|
||||||
|
*
|
||||||
|
* @type {Array}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ANDROID_API_VERSIONS = [
|
||||||
|
[/^9([.]0|)/, 28],
|
||||||
|
[/^8[.]1/, 27],
|
||||||
|
[/^8([.]0|)/, 26],
|
||||||
|
[/^7[.]1/, 25],
|
||||||
|
[/^7([.]0|)/, 24],
|
||||||
|
[/^6([.]0|)/, 23],
|
||||||
|
[/^5[.]1/, 22],
|
||||||
|
[/^5([.]0|)/, 21],
|
||||||
|
[/^4[.]4/, 20],
|
||||||
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the Android API version from the userAgent
|
||||||
|
*
|
||||||
|
* @return {number} version
|
||||||
|
*/
|
||||||
|
|
||||||
|
function getAndroidApiVersion() {
|
||||||
|
if (os !== 'android') return null
|
||||||
|
const { userAgent } = window.navigator
|
||||||
|
const matchData = userAgent.match(/Android\s([0-9\.]+)/)
|
||||||
|
if (matchData == null) return null
|
||||||
|
const versionString = matchData[1]
|
||||||
|
|
||||||
|
for (const [regex, version] of ANDROID_API_VERSIONS) {
|
||||||
|
if (versionString.match(regex)) return version
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export.
|
* Export.
|
||||||
*
|
*
|
||||||
@@ -109,5 +146,9 @@ export const IS_IOS = os === 'ios'
|
|||||||
export const IS_MAC = os === 'macos'
|
export const IS_MAC = os === 'macos'
|
||||||
export const IS_WINDOWS = os === 'windows'
|
export const IS_WINDOWS = os === 'windows'
|
||||||
|
|
||||||
|
export const ANDROID_API_VERSION = getAndroidApiVersion()
|
||||||
|
|
||||||
export const HAS_INPUT_EVENTS_LEVEL_1 = features.includes('inputeventslevel1')
|
export const HAS_INPUT_EVENTS_LEVEL_1 = features.includes('inputeventslevel1')
|
||||||
export const HAS_INPUT_EVENTS_LEVEL_2 = features.includes('inputeventslevel2')
|
export const HAS_INPUT_EVENTS_LEVEL_2 =
|
||||||
|
features.includes('inputeventslevel2') ||
|
||||||
|
(IS_ANDROID && (ANDROID_API_VERSION === 28 || ANDROID_API_VERSION === null))
|
||||||
|
Reference in New Issue
Block a user