Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for svg avatar #44

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@

import * as React from "react";
import {Dimensions, StyleSheet, View} from "react-native";

import {Appbar, Avatar, Menu, Text, TouchableRipple} from "react-native-paper";
import {useNotifications} from "react-native-notificated";
import {useTranslation} from "react-i18next";
import Icon from "react-native-vector-icons/MaterialCommunityIcons";
import {SvgUri} from "react-native-svg";

import CasdoorLoginPage, {useCasdoorLogout} from "./CasdoorLoginPage";
import LoginMethodSelector from "./LoginMethodSelector";
import useStore from "./useStorage";
import {useAccountSync} from "./useAccountStore";
import LoginMethodSelector from "./LoginMethodSelector";
import {useTranslation} from "react-i18next";

const {width} = Dimensions.get("window");

Expand Down Expand Up @@ -111,11 +114,21 @@ const Header = () => {
>
<View style={styles.buttonContent}>
{userInfo !== null && (
<Avatar.Image
size={28}
source={{uri: userInfo.avatar}}
style={styles.avatar}
/>
userInfo.avatar?.endsWith(".svg") ? (
<View style={[styles.avatar, {width: 28, height: 28}]}>
<SvgUri
width="28"
height="28"
uri={userInfo.avatar}
/>
</View>
) : (
<Avatar.Image
size={28}
source={{uri: userInfo.avatar}}
style={styles.avatar}
/>
)
)}
<Text style={[
styles.buttonText,
Expand Down
19 changes: 15 additions & 4 deletions SettingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {ActionSheetProvider} from "@expo/react-native-action-sheet";
import * as Application from "expo-application";
import {useTranslation} from "react-i18next";
import Constants, {ExecutionEnvironment} from "expo-constants";
import {SvgUri} from "react-native-svg";

import CasdoorLoginPage, {useCasdoorLogout} from "./CasdoorLoginPage";
import LoginMethodSelector from "./LoginMethodSelector";
Expand Down Expand Up @@ -62,10 +63,20 @@ const SettingPage = () => {
<Surface style={styles.profileCard} elevation={1}>
{userInfo ? (
<View style={styles.profileInfo}>
<Avatar.Image
size={60}
source={{uri: userInfo.avatar}}
/>
{userInfo.avatar?.endsWith(".svg") ? (
<View style={{width: 60, height: 60}}>
<SvgUri
width="60"
height="60"
uri={userInfo.avatar}
/>
</View>
) : (
<Avatar.Image
size={60}
source={{uri: userInfo.avatar}}
/>
)}
<View style={styles.profileText}>
<Text variant="titleLarge">{userInfo.name}</Text>
<Text variant="bodyMedium" style={{color: theme.colors.secondary}}>
Expand Down
Loading