反応ネイティブアプリ画面適応プロトコル(ドラフト設計による敏感画素ライン)

インポートは、{反応させ
  コンポーネント、
  PropTypes 
「反応」からを}。
インポート{ 
  寸法、
  PixelRatio、
  プラットフォーム、
  ステータスバー、
  ビュー
}反応ネイティブ'から。

せ小道具= {}; 
輸出デフォルトのクラス決議{ 
  静的メソッドget(useFixWidth =真){ 
    useFixWidthを返しますか?{ 
      ... props.fw 
    }:{ 
      ... props.fh 
    } 
  } 

  静的setDesignSize(DWIDTH = 750は、dheight = 1336、DIM = "ウィンドウ"){ 
    せデザインサイズ= { 
      幅:DWIDTH、
      高さ:dheight 
    }。

    navHeight = Platform.OS === 'アンドロイド'しましょうか?StatusBar.currentHeight:0; 
    pxRatio = PixelRatio.get(DIM)しましょう。
    {せ
      、幅、
      高さ
    } = Dimensions.get(DIM)。
    もし(= "画面"薄暗い!)高さ- = navHeight。
    W = PixelRatio.getPixelSizeForLayoutSize(幅)とします。
    せ、H = PixelRatio.getPixelSizeForLayoutSize(高さ)。

    fw_design_scale = designSize.width /ワットをしましょう。
    fw_width = designSize.width。
    fw_height = H * fw_design_scale。
    fw_scale = 1 / pxRatio / fw_design_scale。

    fh_design_scale = designSize.height / Hしましょう。
    * fh_design_scaleワットfh_width =; 
    fh_height = designSize.height。
    fh_scale = 1 / pxRatio / fh_design_scale。

    props.fw = { 
      幅:fw_width、
      高さ:fw_height、
      スケール:fw_scale、
      navHeight 
    }。
    props.fh = { 
      幅:fh_width、
      高さ:fh_height、
      スケール:fh_scale、
      navHeight 
    }。

    console.log( "winSize"、JSON.stringify({ 
      幅、
      高さ
    }))
    はconsole.log( "winPixelSize"、JSON.stringify({ 
      幅W、
      高さ:H 
    }))
    はconsole.log( "pxRatio"、 pxRatio)
    はconsole.log( "fixWidth"、JSON.stringify(props.fw)) 
    はconsole.log( "fixHeight"、JSON.stringify(props.fh))
  } 

  静的FixWidthView =(P)=> { 
    {せ 
      、幅、
      高さ、
      スケール、
      navHeight 
    } = props.fw。
    リターン(< 
      ビュー{ 
        ... P 
      } 
      スタイル= { 
        [p.style、{ 
          marginTop:navHeight、
          幅:幅、
          高さ:高さ、
          変換:[{ 
              移動X:-width * 0.5 
            }、
            { 
              移動Y:-height * 0.5 
            }、
            { 
              スケール:スケール
            }、
            { 
              移動X:幅* 0.5 
            }、
            { 
              移動Y:高さ* 0.5 
            } 
          ] 
        }] 
      } 
      /> 
    )。
  }。

  静的FixHeightView =(P)=> { 
    {せ
      、幅、
      高さ、
      スケール、
      navHeight 
    } = props.fh。
    リターンは、(< 
      ビュー{ 
        ... P 
      } 
      スタイルは= { 
        [p.style、{ 
          marginTop:navHeight、
          幅:幅、
          高さ:高さは、
          変換:[{ 
              移動X:-width * 0.5 
            }、
            { 
              移動Y:-height * 0.5 
            }、
            { 
              スケール:スケール
            }、
            { 
              移動X:幅* 0.5 
            }、
            { 
              移動Y:高さ* 0.5 
            } 
          ] 
        }] 
      } 
      /> 
    )。
  }。
}。
//初期化
Resolution.setDesignSize();

おすすめ

転載: www.cnblogs.com/fanzhen/p/12497637.html