Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复内联样式 vendor prefix 解析错误的问题
Browse files Browse the repository at this point in the history
fix #259
  • Loading branch information
Darmody authored and yesmeck committed Sep 30, 2019
1 parent fbeab45 commit 1e7997d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,31 @@ Object {
}
`;

exports[`remax render renders vendor prefix style 1`] = `
Object {
"children": Array [
Object {
"children": Array [
Object {
"text": "hello",
"type": "plain-text",
},
],
"id": 2,
"props": Object {
"style": "-webkit-line-clamp:2;height:100px;",
},
"text": undefined,
"type": "view",
},
],
"id": 0,
"props": undefined,
"text": undefined,
"type": "root",
}
`;

exports[`remax render umount component 1`] = `
Object {
"children": Array [
Expand Down
9 changes: 9 additions & 0 deletions packages/remax/src/__tests__/alipay/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ describe('remax render', () => {
expect(container.root).toMatchSnapshot();
});

it('renders vendor prefix style', () => {
const Page = () => (
<View style={{ WebkitLineClamp: 2, height: '100px' }}>hello</View>
);
const container = new Container(p);
render(<Page />, container);
expect(container.root).toMatchSnapshot();
});

it('renders empty style', () => {
const Page = () => <View style={undefined}>hello</View>;
const container = new Container(p);
Expand Down
22 changes: 16 additions & 6 deletions packages/remax/src/utils/plainStyle.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { CSSProperties } from 'react';

const transformReactStyleKey = (key: string) =>
key
.replace(/\.?([A-Z]+)/g, function(_x: any, y: string) {
return '-' + y.toLowerCase();
})
.replace(/^-/, '');
const vendorPrefixes = ['webkit', 'moz', 'ms', 'o'];

const transformReactStyleKey = (key: string) => {
let styleValue = key.replace(/\.?([A-Z]+)/g, function(_x: any, y: string) {
return '-' + y.toLowerCase();
});

const firstWord = styleValue.split('-').filter(s => s)[0];
styleValue = styleValue.replace(/^-/, '');

if (vendorPrefixes.find(prefix => prefix === firstWord)) {
styleValue = '-' + styleValue;
}

return styleValue;
};

const plainStyle = (style: CSSProperties | null | undefined) => {
if (!style) {
Expand Down

0 comments on commit 1e7997d

Please sign in to comment.