Skip to content

Commit

Permalink
Merge branch 'master' into fix-unocss-dot
Browse files Browse the repository at this point in the history
  • Loading branch information
hiyuki authored Nov 26, 2024
2 parents 7405cd8 + d9836f3 commit 83ed0ee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
44 changes: 22 additions & 22 deletions packages/core/src/platform/builtInMixins/styleHelperMixin.ios.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import { isObject, isArray, dash2hump, isFunction, cached, getFocusedNavigation } from '@mpxjs/utils'
import { isObject, isArray, dash2hump, cached } from '@mpxjs/utils'
import { Dimensions, StyleSheet } from 'react-native'

let { width, height } = Dimensions.get('screen')

Dimensions.addEventListener('change', ({ screen }) => {
width = screen.width
height = screen.height
})

function rpx (value) {
const { width } = Dimensions.get('screen')
// rn 单位 dp = 1(css)px = 1 物理像素 * pixelRatio(像素比)
// px = rpx * (750 / 屏幕宽度)
return value * width / 750
}
function vw (value) {
const { width } = Dimensions.get('screen')
return value * width / 100
}
function vh (value) {
const navigation = getFocusedNavigation()
const height = navigation?.layout?.height || Dimensions.get('screen').height
return value * height / 100
}

Expand All @@ -24,14 +27,15 @@ const unit = {
}

function formatValue (value) {
let matched
if ((matched = numberRegExp.exec(value))) {
value = +matched[1]
} else if ((matched = unitRegExp.exec(value))) {
value = unit[matched[2]](+matched[1])
} else if (hairlineRegExp.test(value)) {
value = StyleSheet.hairlineWidth
const matched = unitRegExp.exec(value)
if (matched) {
if (!matched[2] || matched[2] === 'px') {
return +matched[1]
} else {
return unit[matched[2]](+matched[1])
}
}
if (hairlineRegExp.test(value)) return StyleSheet.hairlineWidth
return value
}

Expand Down Expand Up @@ -106,8 +110,7 @@ function stringifyDynamicClass (value) {

const listDelimiter = /;(?![^(]*[)])/g
const propertyDelimiter = /:(.+)/
const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh)\s*$/
const numberRegExp = /^\s*(-?\d+(\.\d+)?)(px)?\s*$/
const unitRegExp = /^\s*(-?\d+(?:\.\d+)?)(rpx|vw|vh|px)?\s*$/
const hairlineRegExp = /^\s*hairlineWidth\s*$/
const varRegExp = /^--/

Expand Down Expand Up @@ -164,21 +167,18 @@ export default function styleHelperMixin () {
},
__getStyle (staticClass, dynamicClass, staticStyle, dynamicStyle, hide) {
const result = {}
const classMap = {}
// todo 全局样式在每个页面和组件中生效,以支持全局原子类,后续支持样式模块复用后可考虑移除
if (isFunction(global.__getAppClassMap)) {
Object.assign(classMap, global.__getAppClassMap())
}
if (isFunction(this.__getClassMap)) {
Object.assign(classMap, this.__getClassMap())
}
const classMap = this.__classMap || {}
const appClassMap = global.__appClassMap || {}

if (staticClass || dynamicClass) {
// todo 当前为了复用小程序unocss产物,暂时进行mpEscape,等后续正式支持unocss后可不进行mpEscape
const classString = mpEscape(concat(staticClass, stringifyDynamicClass(dynamicClass)))
classString.split(/\s+/).forEach((className) => {
if (classMap[className]) {
Object.assign(result, classMap[className])
} else if (appClassMap[className]) {
// todo 全局样式在每个页面和组件中生效,以支持全局原子类,后续支持样式模块复用后可考虑移除
Object.assign(result, appClassMap[className])
} else if (this.props[className] && isObject(this.props[className])) {
// externalClasses必定以对象形式传递下来
Object.assign(result, this.props[className])
Expand Down
10 changes: 7 additions & 3 deletions packages/core/src/platform/createApp.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ export default function createApp (option, config = {}) {
createElement(Stack.Navigator,
{
initialRouteName,
headerBackButtonDisplayMode: 'minimal',
headerMode: 'float',
gestureEnabled: true
screenOptions: {
gestureEnabled: true,
// 7.x替换headerBackTitleVisible
// headerBackButtonDisplayMode: 'minimal',
headerBackTitleVisible: false,
headerMode: 'float'
}
},
...getPageScreens(initialRouteName, initialParams)
)
Expand Down
8 changes: 2 additions & 6 deletions packages/webpack-plugin/lib/react/processStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ module.exports = function (styles, {
error
})
if (ctorType === 'app') {
output += `global.__getAppClassMap = function() {
return ${shallowStringify(classMap)};
};\n`
output += `global.__appClassMap = ${shallowStringify(classMap)};\n`
} else {
output += `global.currentInject.injectMethods = {
__getClassMap: function() {
return ${shallowStringify(classMap)};
}
__classMap: ${shallowStringify(classMap)}
};\n`
}
} catch (e) {
Expand Down

0 comments on commit 83ed0ee

Please sign in to comment.