fix(keyboard): support OnePlus PLB110 fallback
This commit is contained in:
@@ -117,4 +117,20 @@ describe("shouldEnableKeyboardAdaptation", () => {
|
|||||||
});
|
});
|
||||||
expect(shouldEnableKeyboardAdaptation(environment)).toBe(false);
|
expect(shouldEnableKeyboardAdaptation(environment)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("enables the fallback for OnePlus PLB110 Facebook in-app browser", () => {
|
||||||
|
const environment = getKeyboardAdaptEnvironment(
|
||||||
|
"Mozilla/5.0 (Linux; Android 15; PLB110 Build/AP3A.240617.008; wv) " +
|
||||||
|
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
|
||||||
|
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A",
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(environment).toMatchObject({
|
||||||
|
isAndroid: true,
|
||||||
|
isOppoFamilyDevice: true,
|
||||||
|
isFacebookInAppBrowser: true,
|
||||||
|
isTargetAndroidFacebookDevice: true,
|
||||||
|
});
|
||||||
|
expect(shouldEnableKeyboardAdaptation(environment)).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,23 +1,52 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
import { PlatformDetector } from "../platform-detect";
|
import {
|
||||||
|
isOnePlusKeyboardFallbackDevice,
|
||||||
|
PlatformDetector,
|
||||||
|
} from "../platform-detect";
|
||||||
|
|
||||||
|
function createOnePlusFacebookUa(model: string): string {
|
||||||
|
return (
|
||||||
|
`Mozilla/5.0 (Linux; Android 15; ${model} Build/AP3A.240617.008; wv) ` +
|
||||||
|
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
|
||||||
|
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
describe("PlatformDetector", () => {
|
describe("PlatformDetector", () => {
|
||||||
it("treats OnePlus PKC110 as an OPPO-family keyboard fallback device", () => {
|
it("treats OnePlus PKC110 as an OPPO-family keyboard fallback device", () => {
|
||||||
const ua =
|
const ua = createOnePlusFacebookUa("PKC110");
|
||||||
"Mozilla/5.0 (Linux; Android 15; OnePlus PKC110 Build/AP3A.240617.008; wv) " +
|
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
|
|
||||||
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A";
|
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOnePlusKeyboardFallbackDevice({
|
||||||
|
model: "PKC110",
|
||||||
|
vendor: "OnePlus",
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
|
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("treats OnePlus PLB110 as an OPPO-family keyboard fallback device", () => {
|
||||||
|
const ua = createOnePlusFacebookUa("PLB110");
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOnePlusKeyboardFallbackDevice({
|
||||||
|
model: "PLB110",
|
||||||
|
vendor: "OnePlus",
|
||||||
|
}),
|
||||||
|
).toBe(true);
|
||||||
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true);
|
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not treat other OnePlus models as OPPO-family fallback devices", () => {
|
it("does not treat other OnePlus models as OPPO-family fallback devices", () => {
|
||||||
const ua =
|
const ua = createOnePlusFacebookUa("NE2210");
|
||||||
"Mozilla/5.0 (Linux; Android 15; NE2210 Build/AP3A.240617.008; wv) " +
|
|
||||||
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " +
|
|
||||||
"Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A";
|
|
||||||
|
|
||||||
|
expect(
|
||||||
|
isOnePlusKeyboardFallbackDevice({
|
||||||
|
model: "NE2210",
|
||||||
|
vendor: "OnePlus",
|
||||||
|
}),
|
||||||
|
).toBe(false);
|
||||||
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(false);
|
expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { UAParser } from "ua-parser-js";
|
import { UAParser } from "ua-parser-js";
|
||||||
|
|
||||||
|
const ONEPLUS_KEYBOARD_FALLBACK_MODELS = new Set(["PKC110", "PLB110"]);
|
||||||
|
|
||||||
export type PlatformName = "ios" | "android" | "desktop" | "unknown";
|
export type PlatformName = "ios" | "android" | "desktop" | "unknown";
|
||||||
|
|
||||||
export interface PlatformInfo {
|
export interface PlatformInfo {
|
||||||
@@ -98,7 +100,10 @@ export class PlatformDetector {
|
|||||||
`${info.deviceVendor} ${info.userAgent}`,
|
`${info.deviceVendor} ${info.userAgent}`,
|
||||||
);
|
);
|
||||||
if (isOnePlusFamily) {
|
if (isOnePlusFamily) {
|
||||||
return /\bPKC110\b/i.test(`${info.deviceModel} ${info.userAgent}`);
|
return isOnePlusKeyboardFallbackDevice({
|
||||||
|
model: info.deviceModel,
|
||||||
|
vendor: info.deviceVendor,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return /\b(OPPO|OPlus|ColorOS|CPH\d{3,})\b/i.test(target);
|
return /\b(OPPO|OPlus|ColorOS|CPH\d{3,})\b/i.test(target);
|
||||||
}
|
}
|
||||||
@@ -114,3 +119,12 @@ export class PlatformDetector {
|
|||||||
return navigator.platform === "MacIntel" && (navigator.maxTouchPoints ?? 0) > 1;
|
return navigator.platform === "MacIntel" && (navigator.maxTouchPoints ?? 0) > 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isOnePlusKeyboardFallbackDevice(
|
||||||
|
device: { model: string; vendor: string },
|
||||||
|
): boolean {
|
||||||
|
if (!/\bOnePlus\b/i.test(device.vendor)) return false;
|
||||||
|
return ONEPLUS_KEYBOARD_FALLBACK_MODELS.has(
|
||||||
|
device.model.trim().toUpperCase(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user