首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Blur在Android @react本地社区/blur上不能正常工作

Blur在Android @react本地社区/blur上不能正常工作
EN

Stack Overflow用户
提问于 2022-07-28 22:45:10
回答 1查看 439关注 0票数 0

BlurVIew包中的Android元素上,定位不正确。它可以在iOS设备上正常工作。但在安卓系统上,包裹在<BlurView>{children}</BlurView>中的元素会相互碰撞。屏幕截图低于

有时,当我在dev模式下更改样式时,它会正常工作,但是当我构建apk时,bug会再次出现。

我怎样才能在Android上修复它呢?

代码语言:javascript
运行
复制
const BottomNavigationTabs: React.FC<BottomTabBarProps> = ({
  descriptors,
  state,
  navigation,
}) => {
  const focusedOptions = descriptors[state.routes[state.index].key].options;

  return (
    <>
        <BlurView blurType="light"
          blurAmount={15} style={{ height: 85, width: '100%', position: 'absolute', bottom: 0, }}>
        <View style={{ display: 'flex', flexDirection: 'row', position: 'absolute', bottom: 0, justifyContent: 'space-between' }}>
        {state.routes.map((route, index) => {
          const { options } = descriptors[route.key];
          const label =
            options.tabBarLabel !== undefined
              ? options.tabBarLabel
              : options.title !== undefined
              ? options.title
              : route.name;

          const isFocused = state.index === index;
          const focusedColor = isFocused ? colors.text1 : colorsOld.black;

          //Weird snippet, to render passed icon just call function with any return value, then just set color
          const icon =
            options.tabBarIcon &&
            React.cloneElement(
              //@ts-ignore
              options.tabBarIcon((props: any) => props),
              { color: focusedColor }
            );

          const onPress = () => {
            const event = navigation.emit({
              type: "tabPress",
              target: route.key,
              canPreventDefault: true,
            });

            if (!isFocused && !event.defaultPrevented) {
              navigation.navigate(route.name);
            }
          };

          const onLongPress = () => {
            navigation.emit({
              type: "tabLongPress",
              target: route.key,
            });
          };

          const tabBtn = (
            <TouchableOpacity
              accessibilityRole="button"
              accessibilityState={isFocused ? { selected: true } : {}}
              accessibilityLabel={options.tabBarAccessibilityLabel}
              testID={options.tabBarTestID}
              onPress={onPress}
              style={styles.tabButton}
              onLongPress={onLongPress}
              activeOpacity={0.7}
              key={route.key}
            >
              <View style={styles.tabItem}>
                <View style={styles.tabItemIcon}>{icon}</View>
                <Text style={{ ...styles.tabItemLabel, color: focusedColor }}>
                  {label}
                </Text>
              </View>
            </TouchableOpacity>
          );
          return tabBtn;
        })}
        </View>
        </BlurView>
    </>
  );
};

const styles = StyleSheet.create({
  container: {
    alignItems: "center",
    justifyContent: "center",
    paddingTop: 9,
    paddingBottom: 15,
  },
  tabButton: {
    paddingTop: 8,
    paddingBottom: 15,
    paddingHorizontal: 10,
    borderRadius: 10,
    zIndex: 10000
  },
  tabsContainer: {
    backgroundColor: colors.secondaryBg(0.5),
    width: "100%",
    left: 0,
    bottom: 0,
    zIndex: 999,
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-around",
  },
  tabItem: {
    justifyContent: "center",
    alignItems: "center",
  },
  tabItemIcon: {
    marginBottom: 6,
  },
  tabItemLabel: {
    fontSize: 12,
    fontFamily: "Inter-Medium",
  },
});
EN

回答 1

Stack Overflow用户

发布于 2022-08-01 08:21:34

在这里找到了一个解决方案,https://github.com/Kureev/react-native-blur/issues/483#issuecomment-1199210714

解决方案是不设置为<BlurView> position: absolute,也不使用它包装任何东西。在我的例子中,看起来是:

代码语言:javascript
运行
复制
import React from "react";
import {
  Text,
  View,
  ImageBackground,
  TouchableOpacity,
  StyleSheet,
} from "react-native";
import { BlurView } from "@react-native-community/blur";
import { BottomTabBarProps } from "@react-navigation/bottom-tabs";

import colorsOld from "src/theme/colorsOld";
import colors from "src/theme/colors";

const BottomNavigationTabs: React.FC<BottomTabBarProps> = ({
  descriptors,
  state,
  navigation,
}) => {
  const focusedOptions = descriptors[state.routes[state.index].key].options;

  return (
      <View
        style={{
          display: "flex",
          flexDirection: "row",
          backgroundColor: colors.secondaryBg(0.5),
          position: "absolute",
          bottom: 0,
          justifyContent: "space-between",
        }}
      >
        <BlurView
          blurType="light"
          blurAmount={15}
          style={{ height: 85, width: "100%", bottom: 0 }}
        />
        <View style={styles.tabsContainer}>
          {state.routes.map((route, index) => {
            const { options } = descriptors[route.key];
            const label =
              options.tabBarLabel !== undefined
                ? options.tabBarLabel
                : options.title !== undefined
                ? options.title
                : route.name;

            const isFocused = state.index === index;
            const focusedColor = isFocused ? colors.text1 : colorsOld.black;

            //Weird snippet, to render passed icon just call function with any return value, then just set color
            const icon =
              options.tabBarIcon &&
              React.cloneElement(
                //@ts-ignore
                options.tabBarIcon((props: any) => props),
                { color: focusedColor }
              );

            const onPress = () => {
              const event = navigation.emit({
                type: "tabPress",
                target: route.key,
                canPreventDefault: true,
              });

              if (!isFocused && !event.defaultPrevented) {
                navigation.navigate(route.name);
              }
            };

            const onLongPress = () => {
              navigation.emit({
                type: "tabLongPress",
                target: route.key,
              });
            };

            const tabBtn = (
              <TouchableOpacity
                accessibilityRole="button"
                accessibilityState={isFocused ? { selected: true } : {}}
                accessibilityLabel={options.tabBarAccessibilityLabel}
                testID={options.tabBarTestID}
                onPress={onPress}
                style={styles.tabButton}
                onLongPress={onLongPress}
                activeOpacity={0.7}
                key={route.key}
              >
                <View style={styles.tabItem}>
                  <View style={styles.tabItemIcon}>{icon}</View>
                  <Text style={{ ...styles.tabItemLabel, color: focusedColor }}>
                    {label}
                  </Text>
                </View>
              </TouchableOpacity>
            );
            return tabBtn;
          })}
        </View>
      </View>
  );
};

const styles = StyleSheet.create({
  container: {
    alignItems: "center",
    justifyContent: "center",
    paddingTop: 9,
    paddingBottom: 15,
  },
  tabButton: {
    paddingTop: 8,
    paddingBottom: 15,
    paddingHorizontal: 10,
    borderRadius: 10,
    zIndex: 10000,
  },
  tabsContainer: {
    width: "100%",
    left: 0,
    bottom: 0,
    zIndex: 999,
    position: 'absolute',
    flexDirection: "row",
    alignItems: "center",
    justifyContent: "space-around",
  },
  tabItem: {
    justifyContent: "center",
    alignItems: "center",
  },
  tabItemIcon: {
    marginBottom: 6,
  },
  tabItemLabel: {
    fontSize: 12,
    fontFamily: "Inter-Medium",
  },
});

export default BottomNavigationTabs;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73159930

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档