728x90
반응형

 

애니메이션 View들을 어떻게 텀을 두고 플레이할까 고민하다가

animated.View 들의 ref 들을 onLayout 콜백에서 index 값의 텀을 두고 실행하게 했다.

 

해당 컴포넌트 코드

 

import { FlatList, TouchableOpacity, View } from 'react-native';
import { upeIp } from './useIp';
import FastImage from 'react-native-fast-image';
import * as Animatable from 'react-native-animatable';
import { useRef } from 'react';

export const Category = () => {
  const { ip } = upeIp();
  const itemRef = useRef<Animatable.View>({});

  return (
    <View style={{ width: '100%', height: 100 }}>
      <FlatList
        horizontal
        showsHorizontalScrollIndicator={false}
        data={ip}
        keyExtractor={(item) => String(item.ipIdx)}
        renderItem={({ item, index }) => {
          return (
            <TouchableOpacity
              onLayout={() =>
                itemRef.current[index].animate(
                  {
                    0: { scale: 0, rotate: '-90deg' },
                    0.5: { scale: 0.5, rotate: '-60deg' },
                    0.75: { scale: 0.8, rotate: '-45deg' },
                    1: { scale: 1.0, rotate: '0deg' },
                  },
                  index * 1000,
                )
              }
            >
              <Animatable.View
                duration={300}
                ref={(ref) => (itemRef.current[index] = ref)}
                style={{
                  width: 100,
                  height: 100,
                  justifyContent: 'center',
                  alignItems: 'center',
                }}
              >
                <View
                  style={{
                    width: 75,
                    height: 75,
                    borderRadius: 50,
                    justifyContent: 'center',
                    alignItems: 'center',
                    shadowColor: '#000',
                    shadowOffset: { width: 3, height: 3 },
                    shadowOpacity: 0.4,
                    shadowRadius: 5,
                    elevation: 3,
                    backgroundColor: 'white',
                  }}
                >
                  <FastImage
                    source={{ uri: item.iconUrl }}
                    style={{
                      width: 75,
                      height: 75,
                      borderRadius: 50,
                    }}
                  />
                </View>
              </Animatable.View>
            </TouchableOpacity>
          );
        }}
      />
    </View>
  );
};

 

아직 미완성이라 style들을 밖으로 빼지않았다.

728x90
반응형
728x90
반응형
 			<View
              style={{
                width: 100,
                height: 100,
                justifyContent: 'center',
                alignItems: 'center',
              }}
            >
              <View
                style={{
                  width: 75,
                  height: 75,
                  borderRadius: 50,
                  justifyContent: 'center',
                  alignItems: 'center',
                  shadowColor: '#000',
                  shadowOffset: { width: 3, height: 3 },
                  shadowOpacity: 0.4,
                  shadowRadius: 5,
                  elevation: 3,
                }}
              >
                <FastImage
                  source={{ uri: item.iconUrl }}
                  style={{
                    width: 75,
                    height: 75,
                    borderRadius: 50,
                  }}
                />
              </View>
            </View>

 

추후 재사용을 위해 메모

728x90
반응형
728x90
반응형

 

이커머스 앱을 준비하면서 당연히 들어가야할 기능중 하나인 주소지 관리를 개발하면서

 

다음 postcode 를 사용하였다.  rn에서 사용하려면 react-native-webview 라이브러리가 설치되어있어야한다.

 

yarn add @actbase/react-daum-postcode

 

yarn add react-native-webview

 

import Postcode from '@actbase/react-daum-postcode';
<Postcode
style={{
width: '100%',
height: '100%',
}}
onError={(e) => console.log(e)}
jsOptions={{ animation: true }}
onSelected={(data) => {
setPostVisible(false);
setZipcode(String(data?.zonecode));
setAddress(data?.address);
console.log(JSON.stringify(data));
}}
/>

 

이런식으로 사용하면된다.

728x90
반응형
728x90
반응형

프론트에서 직접 스토리지에 접근하는건 별로지만,

 

같이 일하는 서버개발자분이 앱에서 바로 S3에 업로드를 부탁하셨다.

 

워낙 라이브러리가 잘되어있어서 업로드를 하는데

 

error code :AccessControlListNotSupported

error message :The bucket does not allow ACLs

 

이라는 에러가 나왔다.

 

AWS 해당 버킷에 들어가서

 

 

편집을 누른 후

 

활성하하면 해결된다.

728x90
반응형
728x90
반응형

jwt decode 를 할 일이 생겼다.

 

yarn add jwt-decode

 

라이브러리를 사용하거나,

 

const parseJwt = (token) => {
try {
return JSON.parse(atob(token.split('.')[1]));
} catch (e) {
console.log('e :::::', e);
return null;
}
};

 

함수를 사용하면되는데,

 

invalid base64 for part #2 (Property 'atob' doesn't exist)

 

라는 에러가 나왔다.

 

app.tsx에서

 

import { decode, encode } from 'base-64';

if (!global.btoa) {
global.btoa = encode;
}

if (!global.atob) {
global.atob = decode;
}
 

 

로 atob / btoa 를 선언해주면 끝

728x90
반응형
728x90
반응형

RN을 하면서 수만가지의 에러를 만났지만, 아직도 처음보는 상황이 많다.

 

xcode로 빌드시, 빌드는 잘되어 index.js 가 돌기시작하고나서,

다음 화면으로 안나가는 일명 'stuck in splash screen' 형태가 나와서

xcode 를 살펴보니, Running 부분이 Paused로 변경되어있었다.

 

정말 감이 안오는 부분이라, 커뮤니티에 물어봤는데,

해당 부분의 태그를 클릭하여

break point 를 풀어주면 정상작동한다.

728x90
반응형
728x90
반응형

animated value를 사용시에 항상

 

const animatedY = useRef(new Animated.Value(0)).current;

이런식으로 useRef를 사용한다.

이는 데이터영역의 state 값들이 변화시에 컴포넌트의 리랜더링이 필수적으로 일어날수밖에 없는 상황에 

애니메이션값을 초기화시키지 않기 위함이다.

 

현재 구현한 애니메이션은 스크롤에 따라 opacity 가 변하고, 헤더의 위치및 높이가 변하고 등등

 

animated.timing 함수를 사용하는 부분과, Animated event 를 사용하는 부분으로 나누어져있다.

 

가끔 0번째에서 첫번째로 넘어갈때, 애니메이션이 끊기는 현상이 발생하여 디버깅해보니,

리랜더링시에 애니메이션이 초기화되서 그런가 싶었던 이유와는 별개로, nativeDriver를 사용하는 쓰레드에서 에러가 생기는것 같았다.

 

따라서 useNativeDriver 을 false 로 주니, 해결되었다.

 

useNativeDriver는 애니메이션 처리 작업을 자바스크립트 엔진이 아닌 네이티브 레벨에서 진행하게 하는 옵션으로 transform, opacity처럼 레이아웃과 관련없는 스타일에만 적용할 수 있다. 예를 들어 레이아웃에 영향을 끼치는 left, width, paddingLeft, marginLeft와 같은 스타일에는 꼭 useNativeDriver를 false로 지정해야 한다.

 

 

728x90
반응형
728x90
반응형

style 에 borderRadius 를 적용하면, 안드로이드에서는 radius가 적용되지만, ios에는 적용이 제대로 되지않는다.

 

<ImageBackground
     style={{
     width: deviceWidth - 2 * wrapperPadding,
     height: cardHeight,
     }}
     imageStyle={{ borderRadius: 15 }}
     source={require('../../assets/example/banner.png')}
></ImageBackground>

 

imageStyle props 에 넣어주면 된다.

728x90
반응형
728x90
반응형

피그마에 적혀있는 fontsize 대로 text style 에 입력하게되면, 기본 os의 글자크기에 영향을 많이 받는다.

 

const { fontScale } = Dimensions.get('window');
export const resizeFont = (fontSize: number) => {
return fontSize / fontScale;
};

로 함수를 만들고

 

해당하는 함수에 figma에 적혀있는 사이즈를 넣으면 os의 크기와 별개로 크기정렬이 잘된다.

728x90
반응형
728x90
반응형

Flatlist 나 scrollview에서 pagingEnabled 를 하면, snap 하는 느낌은 들지만, scroll의 offset 이 맞지않는 경우가 많다..

 

이를 위해

 

const offset = heightScale(600) + 2 * cardVerticalMargin;
const snapToOffsets = useMemo(
() =>
Array.from(Array(DUMMY.length)).map(
(_, index) => index * offset - headerHeight,
),
[DUMMY],
);
 

이런식으로 사용하면,

 

어느 offset들에게 걸릴지가 snapToOffesets props 에 의해 flatlist / scrollview 에 전달된다.

 

pagingEnabled
decelerationRate="fast"
scrollEventThrottle={16}
snapToOffsets={snapToOffsets}

주로 같이쓰는 옵션들이다.

728x90
반응형

+ Recent posts