Overriding styles antd component on V5 - antd

I want to customize the styles of some antd components written in cssinjs.
I created a HOC component to access the theme and override some styles and call it after defining the providers
import { useToken, useStyleRegister } from 'antd/es/theme/internal'
import { prefixCls } from 'Src/constants'
import { ReactNode } from 'react'
import { CSSObject } from '#ant-design/cssinjs'
import { GlobalToken } from 'antd/es/theme/interface'
function getStyleButton(token: GlobalToken): CSSObject {
return {
[`.${prefixCls}-btn`]: {
['&-default']: {
backgroundColor: 'transparent '
}
}
}
}
export const OverloadStyle = (props: { children: ReactNode }) => {
const [theme, token, hashId] = useToken()
useStyleRegister(
{
theme,
token,
hashId,
path: ['OverloadStyle']
},
() => [
getStyleButton(token),
]
)
return <>{props.children}</>
}
but there was a problem with style priority
calling !important is not the best way
how to make those styles which I define were below?
Or are there other more convenient ways to extend the standard styles?

Related

How to show loading when uploading many files in uppy library?

im using uppy library in reactjs, when i tried to upload many files nothing happened until the files uploaded (when selecting files in the window dialog and before getting files). How can i catch the event when i choosed the files in the window dialog and before getting them?
Sample code is stated as follows;
import { useState } from 'react'
import Uppy from '#uppy/core'
import thumbnailGenerator from '#uppy/thumbnail-generator'
import { DragDrop } from '#uppy/react'
import { Card, CardHeader, CardTitle, CardBody } from 'reactstrap'
const FileUploaderMulti = () => {
const [previewArr, setPreviewArr] = useState([])
const uppy = new Uppy({
meta: { type: 'avatar' },
autoProceed: true
})
uppy.use(thumbnailGenerator)
uppy.on('thumbnail:generated', (file, preview) => {
const arr = previewArr
arr.push(preview)
setPreviewArr([...arr])
})
const renderPreview = () => {
if (previewArr.length) {
return previewArr.map((src, index) => <img key={index} className='rounded mt-2 mr-1' src={src} alt='avatar' />)
} else {
return null
}
}
return (
<Card>
<CardHeader>
<CardTitle tag='h4'> Multiple Files Upload</CardTitle>
</CardHeader>
<CardBody>
<DragDrop uppy={uppy} />
{renderPreview()}
</CardBody>
</Card>
)
}
export default FileUploaderMulti

Why do I receive “unrecognized selector sent to instance“ in React Native iOS?

My code works perfectly on Android but it shows an error in iOS.
Error in iOS:
I couldn’t understand this error; is it related to AsyncStorage?
Why this happening on iOS devices?
First File
My imports
import React, {Component} from 'react';
import { Alert, Dimensions, Image, TouchableOpacity, AsyncStorage } from 'react-native';
import { Container, Body, Footer, Header, Input, Item, Left, Text, Title, Right, View, Button, Label, Form} from 'native-base';
import { SimpleLineIcons, Ionicons } from '#expo/vector-icons';
import { NavigationActions } from 'react-navigation';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import { LinearGradient } from 'expo';
import { StatusBar } from "react-native";
import { Grid, Row, Col } from 'react-native-easy-grid';
import Toast, {DURATION} from 'react-native-easy-toast';
import Strings from '../utils/Strings';
var width = Dimensions.get('window').width;
export default class Login extends Component {
static navigationOptions = {
header: null
};
constructor() {
super();
this.state = {
MobileNo: '',
};
}
login = () => {
AsyncStorage.setItem('mobileno', MobileNo);
const { MobileNo } = this.state;
console.log("Expected login number " + MobileNo);
fetch('http://demo.weybee.in/Backend/controller/User_Login.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
mobileno: MobileNo
})
}).then((response) => response.json())
.then((responseJson) => {
// If server response message same as Data Matched
if(responseJson != 'Enter valid phone number') {
const { navigation } = this.props;
// Then open Profile activity and send user email to profile activity.
this.props.navigation.navigate('ForgetPass');
} else {
this.refs.toast.show('Invalid Number', DURATION.LENGTH_LONG);
}
}).catch((error) => {
console.error(error);
});
}
}
Second File
My imports
import React, {Component} from 'react';
import { Alert, Dimensions, Image, TouchableOpacity, AsyncStorage } from 'react-native';
import { Container, Body, Footer, Header, Input, Item, Left, Text, Title, Right, View, Button, Label, Form} from 'native-base';
import { SimpleLineIcons, Ionicons } from '#expo/vector-icons';
import { NavigationActions } from 'react-navigation';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import { LinearGradient } from 'expo';
import { StatusBar } from "react-native";
import { Grid, Row, Col } from 'react-native-easy-grid';
import Toast, {DURATION} from 'react-native-easy-toast'
import Strings from '../utils/Strings';
import OtpInputs from 'react-native-otp-inputs';
var width = Dimensions.get('window').width;
export default class Login extends Component {
static navigationOptions = {
header: null
};
constructor() {
super();
this.state = {
MobileNo: '',
mobileNumber: '',
code: '',
}
}
componentDidMount() {
AsyncStorage.getItem('mobileno').then((mobileNo) => {
if(mobileNo){
this.setState({ mobileNumber: mobileNo });
}
});
}
PTP = () => {
let mobileNumber = JSON.parse(this.state.mobileNumber);
console.log("login number " + mobileNumber);
let {code} = this.state;
console.log(code);
fetch('http://demo.weybee.in/Backend/controller/Get_PTP.php', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
mobileno: mobileNumber,
code: code,
})
}).then((response) => response.json())
.then((responseJson) => {
// If server response message same as Data Matched
if(responseJson != 'Enter valid phone number') {
const { navigation } = this.props;
// Then open Profile activity and send user email to profile activity.
this.props.navigation.navigate('Home');
} else {
this.refs.toast.show('Invalid PTP', DURATION.LENGTH_LONG);
}
}).catch((error) => {
console.error(error);
});
}
}
I think the problem might be with how you're saving MobileNo to AsyncStorage. Isn't MobileNo part of state and shouldn't it be referred to as this.state.MobileNo?
Inside FirstFile, This is where the problem is,
AsyncStorage.setItem('mobileno', MobileNo);
It should be,
AsyncStorage.setItem('mobileno', this.state.MobileNo);
I got this error when passing a null value to AsyncStorage.setItem:
AsyncStorage.setItem('user_id', null) // breaks!
To fix it, I just passed a string as the value of the setItem command:
AsyncStorage.setItem('user_id', 'tupac_without_a_nosering') // good!

How to pass payload of an action to another rxjs operator in redux-observable?

I am using redux-observable with rxjs's tap operator to initialize an ipcRenderer event. Before of that I want to dispatch another action. The question is how to proper pass the payload to the tap operator? -
Note: I want to keep the tap operator at the end of sequence
I have tried to pass it in the action's payload but It is not what I want.. check the example
import { ipcRenderer } from 'electron';
import { map, tap, ignoreElements } from 'rxjs/operators';
import { ofType } from 'redux-observable';
import { pipe } from 'rxjs';
import { togglePackageLoader } from 'models/ui/actions'
import { viewPackageStart} from '../actions';
// I want to pass payload to tap
/* togglePackageLoader returns {
type: 'TOGGLE_LOADER',
payload: {
loading: true,
options: {
opt1: value1,
}
}
}
// i want to avoid passing options to toggleLoader payload..
*/
const viewPackageEpic = pipe(
ofType(viewPackageStart.type),
map(({ payload }) => togglePackageLoader({
loading: true,
options: payload
})),
tap(({ payload: { options } }) => {
ipcRenderer.send('npm-view', options)
}),
ignoreElements()
);
export { viewPackageEpic };
I expected to dispatch toggleLoader first then make the ipcRenderer call
I found a solution that suits my needs. I created another epic which catch the same type. Using ignoreElements after the tap operatator.
const viewPackageEpic = pipe(
ofType(viewPackageStart.type),
map(() => updatePackageLoader({
loading: true
})),
);
const viewPackageLoaderEpic = pipe(
ofType(viewPackageStart.type),
tap(({ payload: { options } }) => {
ipcRenderer.send('npm-view', options)
}),
ignoreElements()
);

navigation Prop is missing for this navigator 3

The navigation Prop is missing for this navigator. In react-navigation 3 you must set up your navigation more directly. I took a look at the documentation regarding this but I'm still having trouble figuring out how I will implement this into my code. What is it that I am doing wrong and how would I fix it. Please provide some assistance.
This is my RootStack.js
import React from 'react';
import { createStackNavigator, createSwitchNavigator } from 'react-navigation';
import SignInScreen from './App/screens/SignInScreen';
import Account from './App/screens/Account';
import Inventory from './App/screens/Inventory';
import Settings from './App/screens/Settings';
import SignUp from './App/screens/SignUp';
import ForgotScreen from './App/screens/ForgotScreen';
import Tournament from './App/screens/Tournament';
import TournamentRsvp from './App/screens/TournamentRsvp';
import Shop from './App/screens/Shop';
import Game from './App/screens/Game';
const routes = {
SignInScreen: {
screen: SignInScreen
},
Account: {
screen: Account
},
Tournament: {
screen: Tournament
},
TournamentRsvp: {
screen: TournamentRsvp
},
Shop: {
screen: Shop
},
Game: {
screen: Game
},
SignUp: {
screen: SignUp
},
ForgotScreen: {
screen: ForgotScreen
},
Settings: {
screen: Settings
},
Inventory: {
screen: Inventory
}
};
class AuthLoadingScreen extends React.Component {
constructor() {
super();
}
}
const AppStack = createStackNavigator(routes, {
headerMode: 'none',
navigationOptions: {
headerVisible: false
},
initialRouteName: 'SignInScreen'
});
const AuthStack = createStackNavigator(
{
SignInScreen: {
screen: SignInScreen
}
},
{
headerMode: 'none',
navigationOptions: {
headerVisible: false
}
}
);
export default createSwitchNavigator(
{
AuthLoading: AppStack,
App: AppStack,
Auth: AuthStack
// AuthLoading: AppStack,
// Auth: AuthStack
},
{
initialRouteName: 'AuthLoading'
}
);
This is my App.js below
import React from 'react';
import { Platform, StatusBar, StyleSheet, View } from 'react-native';
import { AppLoading, Asset, Font, Icon } from 'expo';
import * as firebase from 'firebase';
import { createStackNavigator, createSwitchNavigator } from 'react-navigation';
import { firebaseConfig } from './config.js';
import RootStack from './RootStack';
firebase.initializeApp(firebaseConfig);
export default class App extends React.Component {
render() {
return (
<View style={{ flex: 1 }}>
<RootStack />
</View>
);
}
}
Try to wrap in createAppContainer.
import { createAppContainer, createStackNavigator } from 'react-navigation';
export default createAppContainer(createSwitchNavigator(
{
AuthLoading: AppStack,
App: AppStack,
Auth: AuthStack
// AuthLoading: AppStack,
// Auth: AuthStack
},
{
initialRouteName: 'AuthLoading'
}
));

Can't open a deeplink in foreground with React Native for iOS

We are using firebase deeplinks in a react native application built for both iOS and Android.
Example deeplink: https://monedacacao.page.link/RifKomEk3bhNM9CW9?d=1
Expected behavior:
User scans a QR Code that contains a deeplink in QRScannerScreen
onSuccess (e) is triggered and the link is opened using Linking.openUr()
In ReduxNavigation Firebase.links().onLink() is triggered and redirects the user to SendDestinataryScreen
Actual behavior
In Android this works as intended, but on iOS Linking.openURL(e.data) opens a browser with the Firebase fallback link instead of triggering the Firebase.links.onLin() action.
If the link is clicked from outside the application it behaves as intended. So this problem only occurs when opening the link from inside the application.
QRScannerScreen.js
...
onSuccess (e) {
Linking
.openURL(e.data)
.catch(err => console.error('An error occured', err))
}
...
ReduxNavigation.js
import React from 'react'
import { BackHandler, Platform } from 'react-native'
import { addNavigationHelpers, NavigationActions } from 'react-navigation'
import { createReduxBoundAddListener } from 'react-navigation-redux-helpers'
import { connect } from 'react-redux'
import firebase from 'react-native-firebase'
import AppNavigation from './AppNavigation'
class ReduxNavigation extends React.Component {
constructor (props) {
super(props)
// handle deeplinking
firebase.links().onLink((url) => {
console.log('URL', url)
if (this.props.token) {
this.props.dispatch(NavigationActions.push({
routeName: 'SendDestinataryScreen',
params: { link: url }
}))
} else {
this.props.dispatch(NavigationActions.push({
routeName: 'LoginScreen'
}))
}
})
}
componentDidMount () {
if (Platform.OS === 'ios') return
BackHandler.addEventListener('hardwareBackPress', () => {
const { dispatch, nav } = this.props
// change to whatever is your first screen, otherwise unpredictable results may occur
if (nav.routes.length === 1 && (nav.routes[0].routeName === 'LaunchScreen')) {
return false
}
// if (shouldCloseApp(nav)) return false
dispatch({ type: 'Navigation/BACK' })
return true
})
}
componentWillUnmount () {
if (Platform.OS === 'ios') return
BackHandler.removeEventListener('hardwareBackPress')
}
render () {
return <AppNavigation navigation={addNavigationHelpers({ dispatch: this.props.dispatch, state: this.props.nav, addListener: createReduxBoundAddListener('root') })} />
}
}
const mapStateToProps = state => ({ nav: state.nav, token: state.authentication.token })
export default connect(mapStateToProps)(ReduxNavigation)

Resources