반응형 작업을 할 때 safari 특히 ios 14에서 css상의 많은 이슈가 발생했다.
아래와 같은 코드를 사용하였다.
@supports (-webkit-touch-callout: none) {
...
}
확실한 적용을 위해 theme에 적용해두었던 width 사이즈와 함께 사용해주었다.
${({ theme }) =>
theme.breakpoints.small(css`
@supports (-webkit-touch-callout: none) {
height: -webkit-fill-available;
}
height: 100vh;
height: fill-available;
`)}
`
npm install react-device-detect --save
or
yarn add react-device-detect
훅과 컴포넌트들을 제공하는데
랩핑 컴포넌트 제공
<BrowserView>
<h1>This is rendered only in browser</h1>
</BrowserView>
<MobileView>
<h1>This is rendered only on mobile</h1>
</MobileView>
boolean 값을 반환하는 훅 제공
import {isMobile} from 'react-device-detect';
function App() {
renderContent = () => {
if (isMobile) {
return <div> This content is available only on mobile</div>
}
return <div> ...content </div>
}
render() {
return this.renderContent();
}
}
//hooks/useDeviceData.js /
import { parseUserAgent } from '../../lib/parse';
export function useDeviceData(userAgent) {
const hookUserAgent = userAgent ? userAgent : window.navigator.userAgent
return parseUserAgent(hookUserAgent)
}
//src/lib/parse.js
const UAParser = require('ua-parser-js/dist/ua-parser.min');
export const ClientUAInstance = new UAParser();
export const browser = ClientUAInstance.getBrowser();
export const cpu = ClientUAInstance.getCPU();
export const device = ClientUAInstance.getDevice();
export const engine = ClientUAInstance.getEngine();
export const os = ClientUAInstance.getOS();
export const ua = ClientUAInstance.getUA();
export const setUa = (userAgentString) => ClientUAInstance.setUA(userAgentString);
export const parseUserAgent = (userAgent) => {
if (!userAgent) {
console.error('No userAgent string was provided');
return;
}
const UserAgentInstance = new UAParser(userAgent);
return {
UA: UserAgentInstance,
browser: UserAgentInstance.getBrowser(),
cpu: UserAgentInstance.getCPU(),
device: UserAgentInstance.getDevice(),
engine: UserAgentInstance.getEngine(),
os: UserAgentInstance.getOS(),
ua: UserAgentInstance.getUA(),
setUserAgent: (userAgentString) => UserAgentInstance.setUA(userAgentString),
};
};
위와 같이 다양한 정보를 제공받을 수 있어 반응형에 굉장히 편리한 라이브러리이다.
참고: https://github.com/duskload/react-device-detect
https://developer.mozilla.org/ko/docs/Web/CSS/@supports